-
-
Notifications
You must be signed in to change notification settings - Fork 866
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
JSONSchemaType allows schemas with optional attributes for Types where they are required #2030
Comments
yes, typescript type utilities are not perfect - they push the limits of typescript to the point of type analyser (and my brain) cracking at seams - no way we can complicate it further, I am afraid... cc @erikbrinkman, just in case I am wrong. |
nullable was enforced for optional parameters, but not forbidden for required parameters. This tests and enforces the latter case. fixes ajv-validator#2030
There are two different issues here. The first was ensuring that The second is that Thus after the PR your example will fail, but: interface MyExample {
foo: number;
}
const myExampleSchema: JSONSchemaType<MyExample> = {
type: 'object',
properties: {
foo: {
type: 'number',
},
},
required: [],
} will still pass, and there's not much |
Thank you both for engaging with this and for that bug fix -- honestly that alone will go a long way. (I also want to mention how thankful I am for the TypeScript support that you've built into this library, it's really excellent and I appreciate how complicated it must have been to implement!) |
nullable was enforced for optional parameters, but not forbidden for required parameters. This tests and enforces the latter case. fixes #2030 Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
What version of Ajv are you using? Does the issue happen if you use the latest version?
Using 8.11.0 (latest)
Ajv options object
No options are set
JSON Schema
Validation result, data AFTER validation, error messages
No static analysis issues come out of TypeScript -- it's considered a valid schema for that type.
What results did you expect?
I expected a TypeScript error saying something along the lines of
"foo?" is incompatible with type "foo"
Are you going to resolve the issue?
I don't think I know how to, but happy to make an effort if this is indeed a valid bug.
The text was updated successfully, but these errors were encountered: