You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the example mentioned above, TypeScript error appears:
Type 'null' is not assignable to type 'string'
But in practice, everything works fine. The initial value of "test" property is null and when the form is submitted, yup validates that null is not a correct value. So from TypeScript perspective, the inital value of "test" can be null.
I don't understand why required() type definitions mark the returned type as NonNullable. I've browsed a lot and I found out that there was a discussion about this issue in the past:
The conclusion was that nullable().required() should infer type as T | null. Why has it not been applied in the recent yup versions? If this is not a bug, what is a workaround to make the case presented in the example type-safe? Thanks in advance.
P.S. I'm not looking for "set you initial value as an empty string" advice. This is just a simple example. In real case scenario, test is an object which can be retrieved as a null from the server.
The text was updated successfully, but these errors were encountered:
Hello, let's consider a simple example:
For the example mentioned above, TypeScript error appears:
Type 'null' is not assignable to type 'string'
But in practice, everything works fine. The initial value of "test" property is null and when the form is submitted, yup validates that null is not a correct value. So from TypeScript perspective, the inital value of "test" can be null.
I don't understand why required() type definitions mark the returned type as NonNullable. I've browsed a lot and I found out that there was a discussion about this issue in the past:
DefinitelyTyped/DefinitelyTyped#41789
The conclusion was that nullable().required() should infer type as T | null. Why has it not been applied in the recent yup versions? If this is not a bug, what is a workaround to make the case presented in the example type-safe? Thanks in advance.
P.S. I'm not looking for "set you initial value as an empty string" advice. This is just a simple example. In real case scenario, test is an object which can be retrieved as a null from the server.
The text was updated successfully, but these errors were encountered: