Skip to content
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

如何判断类型中是否有必填字段 #328

Open
xxleyi opened this issue Jan 25, 2022 · 0 comments
Open

如何判断类型中是否有必填字段 #328

xxleyi opened this issue Jan 25, 2022 · 0 comments

Comments

@xxleyi
Copy link
Owner

xxleyi commented Jan 25, 2022

type RequiredKeys<T> = {
  // eslint-disable-next-line @typescript-eslint/ban-types
  [K in keyof T]-?: {} extends Pick<T, K> ? never : K;
}[keyof T];

type HasRequiredKeys<Props> = RequiredKeys<Props> extends { length: number }
  ? RequiredKeys<Props>["length"] extends 0
    ? false
    : true
  : false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant