Skip to content

Latest commit

 

History

History
101 lines (69 loc) · 1.24 KB

File metadata and controls

101 lines (69 loc) · 1.24 KB

typelab / conditions / IfNotExtendsMutually

type IfNotExtendsMutually<T1, T2, Then, Else> = T1 extends T2 ? T2 extends T1 ? Else : Then : Then;

Resolves to Then if T1 is not assignable to T2 or T2 is not assignable to T1, otherwise resolves to Else.

Type Parameters

Type Parameter Default type Description

T1

The first type to compare.

T2

The second type to compare.

Then

The type to return if T1 and T2 are not assignable to each other.

Else

never

The type to return if T1 and T2 are assignable to each other. Defaults to never.

Returns

Then if T1 and T2 are not assignable to each other, Else otherwise.

Example

type Yes = IfNotExtendsMutually<'', string, 'yes', 'no'>; // 'yes'
type No = IfNotExtendsMutually<string, string, 'yes', 'no'>; // 'no'
type YesOrNo = IfNotExtendsMutually<string | number, string, 'yes', 'no'>; // 'yes' | 'no'