-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
initialValues of createFormStore should accept undefined if exactOptionalPropertyTypes is enabled #234
Comments
Can you send me a Modular Forms code example with more details? |
https://www.typescriptlang.org/tsconfig/#exactOptionalPropertyTypes export type FormOptions<TFieldValues extends FieldValues> = Partial<{
initialValues: PartialValues<TFieldValues>;
validateOn: ValidationMode;
revalidateOn: ValidationMode;
validate: ValidateForm<TFieldValues>;
}>; |
Why is this a problem? Instead of undefined you can just not define any |
It can't accept a variable that might be undefined, although I can add const schema = v.object({
name: v.string()
})
const formStore = createFormStore<v.InferInput<typeof schema>>({
validate: valiForm(schema),
initialValues: (() => (Math.random() > 0.5 ? undefined : { name: "str" }))(),
})
/**
Argument of type '{ validate: ValidateForm<{ name: string; }>; initialValues: { name: string; } | undefined; }' is not assignable to parameter of type 'Partial<{ initialValues: { name?: Maybe<string>; }; validateOn: ValidationMode; revalidateOn: ValidationMode; validate: ValidateForm<{ name: string; }>; }>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Types of property 'initialValues' are incompatible.
Type '{ name: string; } | undefined' is not assignable to type '{ name?: Maybe<string>; }'.
Type 'undefined' is not assignable to type '{ name?: Maybe<string>; }'.
*/ But it's just repeating what you've done in the code. function createFormStore({
initialValues = {},
validateOn = 'submit',
revalidateOn = 'input',
validate
} = {}) |
I understand and agree that we should improve this for a better DX. In the meantime, I hope the workaround works for you. |
if
exactOptionalPropertyTypes
is enabled, initialValues won't accept undefined but accpet{}
The text was updated successfully, but these errors were encountered: