Skip to content

Commit 1e37116

Browse files
committed
Extends: explain myself
1 parent 4c40b07 commit 1e37116

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ type ReadonlyEquivalent<X, Y> = Extends<
118118
>;
119119

120120
/**
121-
* Checks if one type extends another.
121+
* Checks if one type extends another. Note: this is not quite the same as `Left extends Right` because:
122+
* 1. If either type is `never`, the result is `true` iff the other type is also `never`.
123+
* 2. Types are wrapped in a 1-tuple so that union types are not distributed - instead we consider `string | number` to _not_ extend `number`. If we used `Left extends Right` directly you would get `Extends<string | number, number>` => `false | true` => `boolean`.
122124
*/
123125
export type Extends<Left, Right> = IsNever<Left> extends true ? IsNever<Right> : [Left] extends [Right] ? true : false
124126

0 commit comments

Comments
 (0)