-
Notifications
You must be signed in to change notification settings - Fork 156
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
Make default
and examples
schema options properties type-safe
#904
Comments
@Not-Jayden Hi, thanks for the suggestion. Unfortunately, this is considered to be out-of-scope as the There are some notes on this at the following URL https://json-schema.org/understanding-json-schema/reference/annotations
So, from the above, making these keywords strictly match the type means that users who need to assign other values there (for the purposes of tooling) would no longer be able to do so. It was generally decided that TB should let any value be assigned. Hope this brings some insights. Will close off this issue for now, but if you have any follow up questions, feel free to post on this thread. Cheers |
@sinclairzx81 Awesome, thanks a lot for sharing that context and for getting back to me so quickly! Looking at the docs, should the
Also skimming the docs further, they also specify for the
and for the
With that in mind, I wonder if it would still be reasonable for it to be type safe by default with a means of opting out of the strict types if needed (maybe via conditional types or overloads), given it should be an exception to the rule that you don't follow the recommendation. That said I understand this might not be considered overly important for the amount of complexity it adds to support, I just wanted to make sure the decision is well considered. For some additional context, I'm particularly flagging this because I was considering to start using const numSchema = Type.Number({default: "Psyche this isn't a number"})
const mockNumValue = Value.Create(numSchema); // TS thinks this is a `number` but it's just the default string value Keen to hear your thoughts :) |
I was wondering if there's any reason the
default
andexamples
properties for schema options couldn't be made type-safe by getting the static type from the first arg.e.g.
This would obviously be a breaking change, but it seems like it should be possible and would be preferable over
any
.I'm also not 100% sure on whether
examples
should be an array or not, that's just how I've seen it used in my experience.The text was updated successfully, but these errors were encountered: