-
Notifications
You must be signed in to change notification settings - Fork 935
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 access properties defined by yup.InferType #946
Comments
I have the same problem. It was OK in version 0.28.1 but it fails in the current version. |
As a (temporary) fix you could use this
|
Facing the same issue |
I am also facing same issue. It looks like it appends ? to property name which is what makes it inaccessible |
Folks this isn't the right place to report type concerns, the types are maintained on DT by other ppl. Please raise them there |
@onursagir; @omid-ebrahimi ; @sudhagar10 ; @kunalpgithub - I don't know if you found a fix for this but the following works for me. I know this is closed. But I believe the fix here is to define the schema as required. I.e. using the provided example const personSchema = Yup.object({
name: Yup.string().required(),
age: Yup.number().required()
}).required()
type Person = Yup.InferType<typeof personSchema>;
const me: Person = {
name: 'Me',
age: 20
} Removes any errors in my case. Hope this helps! |
In case anyone missed it, add |
|
The definitions were recently fixed – without the required() call, a schema can in theory return |
Oh man. This has cost me quite some hours. Thanks for this thread. Now that I look closely, it ís in the Readme.md. Under the Typescript title it uses the @jquense Should it perhaps deserve a comment in that example? (would be happy to contribute that change) |
@tbntdima did |
You probably put required at the end of your schema definition. Try placing it straight after |
I have similar problem. If I put the required after the shape, I got any type, which is not good. If I put after object and before shape, I have the rude never at he beginning of type. React-hooks-form is beepeing about it. |
I got it to work using the solution described here: export type RemoveIndex<T> = {
[K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
};
type FieldForm = RemoveIndex<Yup.InferType<typeof validationSchema>>; |
This solution seems to be the best, when I use the |
Describe the bug
Take for example this code
When I try to access
me.name
orme.age
TypeScript reports an error sayingTo Reproduce
I have written a codesanbox to demostrate the issue https://codesandbox.io/s/musing-breeze-pdx2p?file=/src/index.ts
Expected behavior
Being able to access
me.name
andme.age
without a TypeScript errorThe text was updated successfully, but these errors were encountered: