typelab / conditions / IfNotExtends
type IfNotExtends<T1, T2, Then, Else> = T1 extends T2 ? Else : Then;Resolves to Then if T1 is not assignable to T2, otherwise resolves to Else.
| Type Parameter | Default type | Description |
|---|---|---|
|
|
‐ |
The first type to compare. |
|
|
‐ |
The second type to compare. |
|
|
‐ |
The type to return if |
|
|
|
The type to return if |
Then if T1 is not assignable to T2, Else otherwise.
type Yes = IfNotExtends<string, '', 'yes', 'no'>; // 'yes'
type No = IfNotExtends<'', string, 'yes', 'no'>; // 'no'
type YesOrNo = IfNotExtends<string | number, string, 'yes', 'no'>; // 'yes' | 'no'