-
-
Notifications
You must be signed in to change notification settings - Fork 880
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
Using JSONSchemaType seems a huge build hog #1659
Comments
Not much can be done about it - everything has a price. JSONSchemaType is a complex type level transformation that converts your data interface to the type that JSON Schema should have. It's purpose is to simplify and speed up schema authoring (via code autocomplete) and to avoid mistakes - so it can save hours of debugging time. Depending on your data interface it can take some time to compile. The good thing about it is that its completely optional - you can use ajv without using JSONSchemaType if compilation time is more important... |
It might be worth submitting as an issue to TS - there might be some potential to optimise compilation there. |
@epoberezkin wow, that was closed fast, maybe not advise it as best practice on the ajv site. Other question is there a type which you can use that just does the same as using the `"$schema": "http://json-schema.org/draft-07/schema#" in your json schema? const scheme: JSONSchema = {}; The problem is was describing impacts everything in a normal typescript oriented build, vscode intellisense is also impacted when using @typescript/es-lint. I am guessing there is something that can be optimised, maybe something recursive. maybe related to microsoft/TypeScript#3496 (comment) |
There is SomeJSONSchema - is it what you are looking for? |
The type indeed has to be recursive, and I don’t see any ways to simplify it - TS is not very optimised for complex type transformations… |
This wouldn't be much of an issue if it was just a build time issue but @tommarien is right that it essentially makes your IDE unusable. Users will get put off by this. I have a very powerful Macbook and it slowed down the TS compiler in VS Code to a snail 🐌 |
Hi all, I added the following validation with ajv ^8.6.0 and ajv-formats ^2.1.0. It has a drastic impact on typescript speed in Visual Studio Code. const schema: JSONSchemaType<AnExampleIncomingDto> = {
type: 'object',
properties: {
name: { type: 'string', maxLength: 100 },
email: { type: 'string', format: 'email' },
about: { type: 'string', maxLength: 1000 },
startDate: { type: 'string', format: 'date' },
endDate: { type: 'string', format: 'date' },
requirements: { type: 'string', maxLength: 1000 },
},
required: [
'name',
'email',
'startDate',
'endDate',
'requirements',
],
additionalProperties: false,
};
export const validate = ajv.compile(schema); The validation works great, and build time isn't much a problem since that happens in CI and already can take multiple minutes. Meanwhile, Visual Studio Code, the small validation with typescript above, takes drastically longer to bring up autocompletes and tooltips. Somewhere on the order of between 5 and 25 seconds. I was surprised by this behavior and did not expect it. |
see #1667 (comment) - looks like it's the issue with TS 4.3+ |
What version of Ajv are you using? Does the issue happen if you use the latest version?
ajv@8.6.0
Your typescript code
Typescript compiler error messages
No compilation issues but build time increases drasticly, from around 1,5 secs to 11 secs
By using --generateTrace i discovered that is was related to
UncheckedJSONSchemaType
type.Just changing to
Describe the change that should be made to address the issue?
What can i do to assist or resolve this issue
Are you going to resolve the issue?
Not sure if i can help 🤷
The text was updated successfully, but these errors were encountered: