-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
InferType inconsistent with module implementation #42360
Comments
Interesting idea but I am pretty sure this would break a lot of code. I did consider doing this when inplementing For one the inrerred type would change all of a sudden when users update to the newer versions of the type definition making this a large breaking change. By itself not a reason not to do so, if something is broken it should be fixed. However the semantics of a required property in Yup is not the same as in TypeScript. For example a In general there isn't a one to one match between Yup and TypeScript concepts so this is never going to be perfect. Another example of that is a |
Makes sense - thanks for your thoughtful reply. I understand your reasoning. Closing. ==================================== P.S. @mauricedb Seems fairly easy to implement an export interface ArraySchema<T> extends BasicArraySchema<T[]> {
// ...
nonempty(): NonEmptyArraySchema<T>
}
export interface NonEmptyArraySchema<T> extends Schema<[T, ...T[]]> {
...
} |
For folks who stumble on this: I ended up rolling my own validation library that's more rigorous when it comes to TS type inference: https://github.com/colinhacks/zod |
If you know how to fix the issue, make a pull request instead.
@types/xxxx
package and had problems.Definitions by:
inindex.d.ts
) so they can respond.If you do not mention the authors the issue will be ignored.
I have a suggestion for an improvement to the typings. Happy to submit a PR but I wanted to make sure this change makes sense first.
Currently, the yup package treats all object properties as optional by default:
Yet
yup.InferType
infers the type as:{ asdf: string }
when really it should be{ asdf?: string }
.The idea behind this change is to make all calls to
yup.string
,yup.number
, andyup.boolean
optional by default, which aligns with the behavior of the actual package implementation. I have this working on my local machine, but I wanted to run this by you guys in case there's a reason it's currently done this way.The text was updated successfully, but these errors were encountered: