Repository navigation
fix(form-core): keep optional schema properties optional in looseSchema #2477
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
base: alpha
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/form-core': patch | ||
| --- | ||
|
|
||
| Fix: `formOptions.looseSchema` no longer turns optional schema properties into required ones, so the same schema can be passed to `validators[].run`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,8 +35,21 @@ export type InferUnion<TBase, TIncoming> = TBase extends BuiltInType | |
| type InferUnionObject< | ||
| in out TBase extends object, | ||
| in out TIncoming extends object, | ||
| > = { | ||
| [K in keyof TBase | keyof TIncoming]: K extends keyof TBase | ||
| > = InferUnionProps< | ||
| TBase, | ||
| TIncoming, | ||
| { | ||
| [K in keyof TBase as K extends keyof TIncoming ? never : K]: unknown | ||
| } & { [K in keyof TIncoming]: unknown } | ||
| > | ||
|
|
||
| // Mapping over `keyof TKeys` (a type parameter) is homomorphic, so each key | ||
| // keeps the `?` modifier it has in `TKeys`. Keys that `TIncoming` declares take | ||
| // its modifier, so a schema input that omits a property stays assignable. | ||
| // Keys only in `TBase` keep theirs. Mapping over | ||
| // `keyof TBase | keyof TIncoming` directly would drop every modifier. | ||
| type InferUnionProps<TBase, TIncoming, TKeys> = { | ||
| [K in keyof TKeys]: K extends keyof TBase | ||
|
Comment on lines
+38
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the type instantiations like with this change? Seems to potentially add a ton of intersection work.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested on the existing form-core type tests, this adds about 0.8% instantiations and check time is unchanged. But this only covers the existing tests with small schemas, so I have not checked the deeply nested ones or the large ones.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll test this out with larger schemas later. Shouldn't change the percentage all that much, especially if it's not copying zod types around. |
||
| ? K extends keyof TIncoming | ||
| ? InferUnion<TBase[K], TIncoming[K]> | ||
| : TBase[K] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.