Skip to content

Latest commit

 

History

History
100 lines (68 loc) · 1.05 KB

File metadata and controls

100 lines (68 loc) · 1.05 KB

typelab / conditions / IfIntersected

type IfIntersected<T1, T2, Then, Else> = T1 & T2 extends never ? Else : Then;

Resolves to Then if T1 is intersected with T2, 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 is intersected with type T2.

Else

never

The type to return if T1 is not intersected with type T2. Defaults to never.

Returns

Then if T1 & T2 is not never, Else otherwise.

Example

type Yes = IfIntersected<'a' | 'c', 'a' | 'b', 'yes', 'no'>; // 'yes'
type No = IfIntersected<'c', 'a' | 'b', 'yes', 'no'>; // 'no'