type Result1 = IfExtends<string, string | number, true, false>; // is true
type Result2 = IfExtends<number, string | number, true, false>; // is true
type Result3 = IfExtends<boolean, string | number, true, false>; // is false
type IsString<T> = IfExtends<T, string, true, false>;
type IsNumber<T> = IfExtends<T, number, true, false>;
type TestString = IsString<string>; // is true
type TestNumber = IsNumber<number>; // is true
type TestBoolean = IsNumber<boolean>; // is false
Conditional type that checks if type
T
extends typeP
. IfT
extendsP
, the type resolves toDo
; otherwiseElse
.