I write a function: createMyForm
, I hope that fields[].prop
must be the property of initialValue
, but this code can’t do it,
type FieldConfig<K> = {
prop: K;
value?: any;
}
function createMyForm<
V extends Record<string, any>,
K extends string = Exclude<keyof V, symbol | number>,
>(
{ initialValue, fields = [] }: {
initialValue: V;
fields?: FieldConfig<K | `${K}.${string}` | `${K}[${string | number}]`>[];
}) { return; }
const initVal = { a: 1, b: '2' };
// why x2 not show error