首页 > 其他分享 >TypeScript Utility Types All In One

TypeScript Utility Types All In One

时间:2022-10-15 09:56:41浏览次数:73  
标签:www TypeScript https xgqfrms com Types Utility

TypeScript Utility Types All In One

Awaited<Type>
Partial<Type>
Required<Type>
Readonly<Type>
Record<Keys, Type>
Pick<Type, Keys>
Omit<Type, Keys>
Exclude<UnionType, ExcludedMembers>
Extract<Type, Union>
NonNullable<Type>
Parameters<Type>
ConstructorParameters<Type>
ReturnType<Type>
InstanceType<Type>
ThisParameterType<Type>
OmitThisParameter<Type>
ThisType<Type>
Intrinsic String Manipulation Types
Uppercase<StringType>
Lowercase<StringType>
Capitalize<StringType>
Uncapitalize<StringType>

https://www.typescriptlang.org/docs/handbook/utility-types.html

Pick<Type, Keys>

interface Todo {
  title: string;
  description: string;
  completed: boolean;
}

// `挑选出`一些字段/属性 构成子集
type TodoPreview = Pick<Todo, "title" | "completed">;

const todo: TodoPreview = {
  title: "Clean room",
  completed: false,
};

todo;
// const todo: TodoPreview

https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys

Omit<Type, Keys>


https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys

Record<Keys, Type>

refs

TypeScript Advanced Types All In One

https://www.cnblogs.com/xgqfrms/p/15877490.html

https://github.com/xgqfrms/learn-typescript-by-practice/issues/21

https://github.com/xgqfrms/learn-typescript-by-practice/issues/22

https://github.com/xgqfrms/learn-typescript-by-practice/issues/23



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载

标签:www,TypeScript,https,xgqfrms,com,Types,Utility
From: https://www.cnblogs.com/xgqfrms/p/16793600.html

相关文章