Created
February 16, 2023 07:33
-
-
Save happyincent/7722d70b22339dedab9552270b37ca1b to your computer and use it in GitHub Desktop.
A workaround to get autocomplete work in yup.object with Partial keys of an existing type.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Shape<T, K extends keyof T> = { [key in K]?: yup.ISchema<T[key]> | ReturnType<typeof yup.ref<T[key]>> }; | |
export type YupObjectType<T> = Pick<T, keyof T>; | |
export type YupObjectShape<T> = Shape<T, keyof T>; | |
// Usage: yup.object<YupObjectType<T>, YupObjectShape<T>>({ ... }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment