[TS] Type Manipulation
keywords: generics
, conditional type
, Mapped Types
, keyof
, typeof
, infer
Conditional Type
Conditional Types @ TypeScript > Handbook > Type Manipulation
// 如果 SomeType 能夠滿足 OtherType 則 SomeType 為 TrueType;否則為 FalseType
NewType = SomeType extends OtherType ? TrueType : FalseType;
要看是否符合某個條件,可以用:
// type T = [想檢驗的條件] ? true : false
type T = 30 extends number ? true : false;