Skip to content

Commit c58888c

Browse files
committed
Add resolution definition
1 parent f163b6e commit c58888c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

conditional-types.md

+16
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,20 @@ The restrictive instantiation will map all type parameters to the input paramete
280280
M[Top](X extends string) === (X extends unknown)
281281
```
282282

283+
We may now define conditional type resolution.
284+
285+
#### Definition - _Conditional Type Resolution_
286+
287+
Define `resolve(T extends U ? A : B, M)` as:
288+
- Let `Check = M(T)` and `Ext = M(U)`.
289+
- If `Check` is the wildcard type `*` then resolve to `*`.
290+
- If `Ext` is the wildcard type `*` then resolve to `*`.
291+
- If at least one of `Check` or `Ext` is a type parameter `X`, or a generic mapped type, return the deferred conditional type `|Check| extends Ext ? A : B`.
292+
- The operator `|T|` on types will strip type substitutions from `T` when `T` is a substitution type.
293+
- If `Ext` is the type `any` or the type `unknown` resolve to `M(A)`.
294+
- If `Check` is the type `any` resolve to `M(A) | M(B)`.
295+
- If `M[*](Check)` is not assignable to `M[*](Ext)` resolve to `M(B)`.
296+
- If `M[Top](Check)` is assignable to `M[Top](Ext)` resolve to `M(A)`.
297+
- Otherwise, return the deferred conditional type `|Check| extends Ext ? A : B`.
298+
283299
## Typing Relations

0 commit comments

Comments
 (0)