-
-
Notifications
You must be signed in to change notification settings - Fork 877
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
Can't create JTDSchemaType from tagged union with no additional properties #2123
Comments
cc @erikbrinkman :) |
Thanks for finding this! Every time there's a bug I heave a sigh because it's partially caused by typescripts weird type system. In general typescript types are permissive, meaning The only exception to this rule is with object literals, which can't specify extra members. That means when creating these schema types, since we're using them mainly for object literals, we're actually bending the type system behave in a way it doesn't normally. For discriminators we remove the discriminator field from the definition with an There may be clever ways to handle this better, but the PR I submitted #2158 just special cases that object, since it's already tricky enough to work with.. |
Thanks for explaining. Now I understand why it wasn't working before. I will keep track of the pull request so I can remove my hackish workaround when it gets merged. |
What I'm trying to do
I want to use the JTDSchemaType to create a schema for messages I will pass through a websocket. The messages have a
type
field used with a discriminator in the schema. Some of the messages require no additional information, such as a "ping" message, but I am getting an error when creating theJTDSchemaType
unless there are additional properties.What version of Ajv are you using? Does the issue happen if you use the latest version?
v8.11
Ajv options object
Your code
What results did you expect?
I expect to be able to create a schema for a tagged union that has no properties except the tag. I can't compile this because typescript expects the mapping of
ping
to be typenever
.Are you going to resolve the issue?
I'm not sure how, but I'm happy to help.
The text was updated successfully, but these errors were encountered: