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 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 & T2 is not never, Else otherwise.
type Yes = IfIntersected<'a' | 'c', 'a' | 'b', 'yes', 'no'>; // 'yes'
type No = IfIntersected<'c', 'a' | 'b', 'yes', 'no'>; // 'no'