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
What results did you expect?
There is a change in the way the validate function narrows the type of its parameter.
Using typescript until 5.0, the type of foo at the bookmark [1] in the above example, matches the type passed as a generic to the getSchema function.
Using typescript 5.1, the type of foo at the bookmark [1] does not change and stay Bar
I have checked the Typescript Changelog but I have not found any lead on what might have changed
Here is a repo with the minimal code to reproduce. If you switch the version of typescript between 5.0 and 5.1, you will notice the change in the narrowing behaviour line 37 of the Validator.ts file.
Are you going to resolve the issue?
I don't think I have the skills to do this but I will check ajv source code.
The text was updated successfully, but these errors were encountered:
in case it helps, I came across this issue from a different angle and found some interesting behavior. I've got an example here that works fine.
Key differences:
I added as const to the FooSchema.
I use compile, not getSchema. I suspect the as const is lost somewhere inside of getSchema
I changed the Bar type to accept numbers or booleans, so that we can more easily see that the type guard is working
Now the above example works great, and I hope many people stuck on this can use it to move forward. But in addition to getSchema not working, I'm finding compile doesn't consistently work. I created a separate ticket for that, because my example seems different enough that these might be unrelated.
What version of Ajv are you using? Does the issue happen if you use the latest version?
Used version: 8.12.0
Ajv options object
JSON Schema
Sample data
Your code
What results did you expect?
There is a change in the way the
validate
function narrows the type of its parameter.Using typescript until 5.0, the type of
foo
at the bookmark [1] in the above example, matches the type passed as a generic to thegetSchema
function.Using typescript 5.1, the type of foo at the bookmark [1] does not change and stay
Bar
I have checked the Typescript Changelog but I have not found any lead on what might have changed
Here is a repo with the minimal code to reproduce. If you switch the version of typescript between 5.0 and 5.1, you will notice the change in the narrowing behaviour line 37 of the Validator.ts file.
Are you going to resolve the issue?
I don't think I have the skills to do this but I will check ajv source code.
The text was updated successfully, but these errors were encountered: