Skip to content

Instantly share code, notes, and snippets.

@happyincent
Created February 16, 2023 07:33
Show Gist options
  • Save happyincent/7722d70b22339dedab9552270b37ca1b to your computer and use it in GitHub Desktop.
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.
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