-
-
Notifications
You must be signed in to change notification settings - Fork 872
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
Nullable doesn't cover unions with null in it #2310
Comments
I believe this is the same as: #1664 This is the workaround I'm using: type MyClass = {
field: number | null;
}
const nullable = <T>(input: T): T => {
return { anyOf: [input, { type: 'null' }] } as T;
};
const schema: JSONSchemaType<MyClass> = {
// ...
properties: {
field: nullable({ type: 'number' })
}
} The |
The story you mentioned isn't exactly the same. Also I get that you can trick TS into accepting the values, but my point is that null unions and nullable should be considered the same thing rather than being a type error (especially considering it doesn't handle unions properly in genera making it impossible to properly validate them without tricking TS). |
Duplicate: #2163 |
Closing as it is a duplicate of #2163 |
What version of Ajv are you using? Does the issue happen if you use the latest version?
8.12.0
Your typescript code
Typescript compiler error messages
Describe the change that should be made to address the issue?
Nullable should cover unions which include null.
Are you going to resolve the issue?
I would love for this to be resolved but I don't have enough experience with the internals of AJV to solve this type error myself. I would prefer it if someone who maintains this library would take a look at this.
The text was updated successfully, but these errors were encountered: