TS Conditional Type

Created
Created
2021 Jun 7 9:17
Tags
Tags
분기를 수행하면서, 타입을 추론하는 방법
TS Conditional Types
type Example1 = Dog extends Animal ? number : string;
 
 
type Entry = "In" | "Out"; type InOrOut<Type extends `fade${string}`> = Type extends `fade${infer Return}` ? Return : never; // type I = "In" type In = InOrOut<"fadeIn">; // type O = "Out" type Out = InOrOut<"fadeOut">;
 
 
 
 
 

Recommendations