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

实现 Pick 类型, 从类型 T 中挑选部分属性 K 构造新的类型 #23

Open
keqing77 opened this issue Mar 7, 2024 · 1 comment
Labels
TypeScript TypeScript 手撕代码 手撕代码

Comments

@keqing77
Copy link
Owner

keqing77 commented Mar 7, 2024

type Todo = {
  id:number;
  title: string;
  desc: string;
  completed: boolean;
}

type A = MyPick<Todo, "title" | "completed">

// 实现的效果
type A = {
  title: string;
  completed: boolean;
}
@keqing77 keqing77 added 手撕代码 手撕代码 TypeScript TypeScript labels Mar 7, 2024
@keqing77
Copy link
Owner Author

keqing77 commented Mar 7, 2024

type MyPick<T, K extends keyof T> = {
  [P in K]: T[P];
};

// Pick<Type, Keys>  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TypeScript TypeScript 手撕代码 手撕代码
Projects
None yet
Development

No branches or pull requests

1 participant