New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type for form.change does not allow nested object keys #391
Comments
Any update on this? |
btw the flow types allow any string as a field name |
Now, with TS 4.3, maybe we can consider some improvement on form.change and some other methods: interface FormApi<FormValues = Record<string, any>> {
change: <Path extends AllPathsOf<FormValues>>(
name: Path,
value?: Partial<ValueMatchingPath<FormValues, Path>>
) => void;
} We can replace |
This won't work because of arrays. I think we should revert types to |
@Dema Path can handle array, React Hook Form already has this feature. |
What is the current behavior?
Setting the value of a nested object results in a typescript error:
results in:
Argument of type 'string' is not assignable to parameter of type ...
What is the expected behavior?
Not sure, maybe it should allow any string since we cannot create a dynamic string type.
Not yet at least maybe something to be revisited in the future,
see: microsoft/TypeScript#6579 and microsoft/TypeScript#41160
Workaround
Casting the string using the
as
keywordSometimes this is not enough because the first parameter is used to infer the type of the second parameter.
Then you will have to cast the value as well:
And if the types diverge too much typescript won't allow that and you'll have to cast to unknown first:
The text was updated successfully, but these errors were encountered: