Open CPPAlien opened 4 years ago
Pick<User, "id" | "age">
Partial
Required
T extends U ? X : Y
Exclude
// 相当于: type A = 'a' type A = Exclude<'x' | 'a', 'x' | 'y' | 'z'>
Omit
// 相当于: type PickUser = { age: number; name: string; } type OmitUser = Omit<User, "id">
-is TypeScript will narrow that variable to that specific type if the original type is compatible
is
function isFish(pet: Fish | Bird): pet is Fish { return (pet as Fish).swim !== undefined; } if (isFish(pet)) { pet.swim(); }
as 强转
Record
type Record<K extends keyof any, T> = { };
-Dictionary
interface Dictionary<T> { [index: string]: T; };
Pick<User, "id" | "age">
Partial
Required
T extends U ? X : Y
Exclude
Omit
-
is
TypeScript will narrow that variable to that specific type if the original type is compatibleas 强转
Record
-Dictionary