-
-
Notifications
You must be signed in to change notification settings - Fork 438
Type inference does not work correctly after 1.2.3 #1391
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
Comments
There might be something wrong with CodeSandbox, if I just click the link it opens up with a few errors already on the imports which doesn't seem related to the issue. With that said, thanks for the report. I think the types are breaking on discriminated unions. A minimal example: type FormData = { name: string } & ({ variant: "foo" } | { variant: "bar"; baz: string }); |
Can you please try to install this version and check if the issue is fixed for you?
|
@Balastrong I tested your pr and it didn't fix my issue. See https://codesandbox.io/p/devbox/affectionate-bardeen-p975cm |
@Balastrong Also confirming that this is occurring for me and #1393 did not fix it either |
That's not how You should use useFieldContext when you define a field component, then follow the other steps in the docs/example to connect all the steps.
Can you please provide an example or more details? "Doesn't work for me" unfortunately doesn't help anyone. |
This seems to fix the issue. Many thanks |
Thanks! This is now available in |
I still have this issue with |
Can you please share an example to reproduce the issue? The original one is fixed, in case we missed an edge case please let us know. |
Of course, here's a short snippet. Is it sufficient in that form, or should I prepare a codesandbox project? import { useForm } from "@tanstack/react-form";
export type MyType = { type: "a" } | { type: "b" };
function useMyType(): { myType: MyType } {
return {
myType: {
type: "a",
},
};
}
export function MyForm() {
const { myType } = useMyType();
const form = useForm({
defaultValues: {
name: "",
myType,
},
});
return (
<form
onSubmit={(e) => {
e.preventDefault();
e.stopPropagation();
form.handleSubmit();
}}
>
<form.Field name="name">
{(field) => (
<input
type="text"
value={field.state.value}
// here's the typescript error: string is not assignable to type 'never'
onChange={(e) => field.handleChange(e.target.value)}
/>
)}
</form.Field>
</form>
);
} |
Thanks! Keys are now properly inferred but there's still something not working on values |
Can you try again with v1.3.2? |
@Balastrong still broken for me here is my reproduction the actually issue seems to be my type of my content field if I remove the content field then my actual filters field starts playing nice otherwise it just becomes any. Note: I only set that content field as a full blob so don't really need the deep access on it but I still want it to be typed potentially there is a better way to describe it |
Thanks! Looks like the value type inference now breaks if there's an explicit You can see that even with this, if you comment or give a proper type to foo it works. type FormData = {
name: string;
foo: any;
} |
Handling of I'll try to close this issue again but please if you spot some more types that aren't inferred right, let us know! Thank you everyone! |
Describe the bug
With 1.2.3, type inference works as expected (via DeepKeys).
With 1.2.4, and up, type inference doesn't appear to be working correctly.
Your minimal, reproducible example
https://codesandbox.io/p/devbox/tender-elbakyan-pdsmh4?file=%2Fsrc%2FScheduleForm.tsx%3A74%2C43
Steps to reproduce
Expected behavior
I expected version 1.2.4 to behave in a similar way to 1.2.3
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
TanStack Form adapter
react-form
TanStack Form version
1.2.4
TypeScript version
5.7.2
Additional context
No response
The text was updated successfully, but these errors were encountered: