Open knee-cola opened 2 years ago
This is based on the info displayed by the VS Code's Intellisense.
Sorry, I would not trust what VS Code Intellisense shows... Please check the output of typescript compiler. If VSCode shows errors where typescript doesn't it should be reported to VSCode, not elsewhere ;)
I'm not sure this is the AJV issue or a TypeScript thing ...
The way you describe, it's VSCode thing :) please share tsc error output, if any.
I thought I was going crazy. Thank you so much for posting the workaround 🙏
Unfortunately the bug also occurs for function parameters:
function myFunction(schema: JSONSchemaType<{ someProperty: boolean }>) {
// schema.properties?: any
schema.properties.abc = ''; // no complaints from tsc
}
Since tsc doesn't complain, I don't think vscode is to blame. It happens with both typescript@4.7.2 and 4.8.3.
EDIT: I do not recommend using the mentioned workaround, it appears to make the ts-server very crashy.
When a schema gets imported to another file it's properties all get assigned
any
type.This is based on the info displayed by the VS Code's Intellisense.
Here's an example I've tested inside a cloned Ajv repo v8.11.0:
The following snippet contains the schema definition for a Car object:
As you can see the list line of the previous snippet, the type of the
properties
equalsUncheckedPropertiesSchema<Car> | undefined
, as expected.This changes if you try importing and using this schema in another file:
As you can see
properties
has been assignedany
type.I've managed to create a workaround which does help with this issue but does not fix it.
The following file shows the workaround (only the last line has been added - the rest is unchanged):
Now in our
BmwCarSchema
file use the newly exported value:As you can see now the
properties
property is correctly typed (the last line).I'm not sure this is the AJV issue or a TypeScript thing ...