Skip to content

Commit d4a3126

Browse files
committed
Port tsgo PR 1284
1 parent 6758cd9 commit d4a3126

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

src/compiler/types.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6265,6 +6265,12 @@ export interface SerializedTypeEntry {
62656265
trackedSymbols: readonly TrackedSymbol[] | undefined;
62666266
}
62676267

6268+
// Note that for types of different kinds, the numeric values of TypeFlags determine the order
6269+
// computed by the CompareTypes function and therefore the order of constituent types in union types.
6270+
// Since union type processing often bails out early when a result is known, it is important to order
6271+
// TypeFlags in increasing order of potential type complexity. In particular, indexed access and
6272+
// conditional types should sort last as those types are potentially recursive and possibly infinite.
6273+
62686274
// dprint-ignore
62696275
export const enum TypeFlags {
62706276
Any = 1 << 0,
@@ -6289,11 +6295,11 @@ export const enum TypeFlags {
62896295
TypeParameter = 1 << 19, // Type parameter
62906296
Object = 1 << 20, // Object type
62916297
Index = 1 << 21, // keyof T
6292-
IndexedAccess = 1 << 22, // T[K]
6293-
Conditional = 1 << 23, // T extends U ? X : Y
6298+
TemplateLiteral = 1 << 22, // Template literal type
6299+
StringMapping = 1 << 23, // Uppercase/Lowercase type
62946300
Substitution = 1 << 24, // Type parameter substitution
6295-
TemplateLiteral = 1 << 25, // Template literal type
6296-
StringMapping = 1 << 26, // Uppercase/Lowercase type
6301+
IndexedAccess = 1 << 25, // T[K]
6302+
Conditional = 1 << 26, // T extends U ? X : Y
62976303
Union = 1 << 27, // Union (T | U)
62986304
Intersection = 1 << 28, // Intersection (T & U)
62996305
/** @internal */

tests/baselines/reference/api/typescript.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6590,19 +6590,19 @@ declare namespace ts {
65906590
TypeParameter = 524288,
65916591
Object = 1048576,
65926592
Index = 2097152,
6593-
IndexedAccess = 4194304,
6594-
Conditional = 8388608,
6593+
TemplateLiteral = 4194304,
6594+
StringMapping = 8388608,
65956595
Substitution = 16777216,
6596-
TemplateLiteral = 33554432,
6597-
StringMapping = 67108864,
6596+
IndexedAccess = 33554432,
6597+
Conditional = 67108864,
65986598
Union = 134217728,
65996599
Intersection = 268435456,
66006600
Literal = 15360,
66016601
Unit = 97292,
66026602
Freshable = 80896,
66036603
StringOrNumberLiteral = 3072,
66046604
PossiblyFalsy = 15868,
6605-
StringLike = 100664352,
6605+
StringLike = 12583968,
66066606
NumberLike = 67648,
66076607
BigIntLike = 8320,
66086608
BooleanLike = 4352,
@@ -6611,9 +6611,9 @@ declare namespace ts {
66116611
VoidLike = 20,
66126612
UnionOrIntersection = 402653184,
66136613
StructuredType = 403701760,
6614-
TypeVariable = 4718592,
6615-
InstantiableNonPrimitive = 29884416,
6616-
InstantiablePrimitive = 102760448,
6614+
TypeVariable = 34078720,
6615+
InstantiableNonPrimitive = 117964800,
6616+
InstantiablePrimitive = 14680064,
66176617
Instantiable = 132644864,
66186618
StructuredOrInstantiable = 536346624,
66196619
Narrowable = 536575971,

tests/baselines/reference/awaitedTypeNoLib.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error TS2318: Cannot find global type 'String'.
1010
awaitedTypeNoLib.ts(3,15): error TS2304: Cannot find name 'PromiseLike'.
1111
awaitedTypeNoLib.ts(18,27): error TS2345: Argument of type 'Thenable<NotPromise<TResult>> | NotPromise<TResult>' is not assignable to parameter of type 'Thenable<TResult>'.
1212
Type 'NotPromise<TResult>' is not assignable to type 'Thenable<TResult>'.
13-
Type '(TResult extends PromiseLike<unknown> ? never : TResult) | TResult' is not assignable to type 'Thenable<TResult>'.
13+
Type 'TResult | (TResult extends PromiseLike<unknown> ? never : TResult)' is not assignable to type 'Thenable<TResult>'.
1414
Type 'Thenable<unknown> & TResult' is not assignable to type 'Thenable<TResult>'.
1515
Type 'unknown' is not assignable to type 'TResult'.
1616
'TResult' could be instantiated with an arbitrary type which could be unrelated to 'unknown'.
@@ -49,7 +49,7 @@ awaitedTypeNoLib.ts(18,27): error TS2345: Argument of type 'Thenable<NotPromise<
4949
~~~~~~
5050
!!! error TS2345: Argument of type 'Thenable<NotPromise<TResult>> | NotPromise<TResult>' is not assignable to parameter of type 'Thenable<TResult>'.
5151
!!! error TS2345: Type 'NotPromise<TResult>' is not assignable to type 'Thenable<TResult>'.
52-
!!! error TS2345: Type '(TResult extends PromiseLike<unknown> ? never : TResult) | TResult' is not assignable to type 'Thenable<TResult>'.
52+
!!! error TS2345: Type 'TResult | (TResult extends PromiseLike<unknown> ? never : TResult)' is not assignable to type 'Thenable<TResult>'.
5353
!!! error TS2345: Type 'Thenable<unknown> & TResult' is not assignable to type 'Thenable<TResult>'.
5454
!!! error TS2345: Type 'unknown' is not assignable to type 'TResult'.
5555
!!! error TS2345: 'TResult' could be instantiated with an arbitrary type which could be unrelated to 'unknown'.

tests/baselines/reference/partiallyNamedTuples2.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ const matches = x.get(id1);
4949
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5050
>x.get(id1) : Iterable<[id2: string, object]>
5151
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
52-
>x.get : <Key extends [] | [id1: string] | [id1: string, id2: string]>(...key: Key) => GetResult<[id1: string, id2: string], Key, object>
52+
>x.get : <Key extends [id1: string, id2: string] | [id1: string] | []>(...key: Key) => GetResult<[id1: string, id2: string], Key, object>
5353
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5454
>x : MultiKeyMap<[id1: string, id2: string], object>
5555
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56-
>get : <Key extends [] | [id1: string] | [id1: string, id2: string]>(...key: Key) => GetResult<[id1: string, id2: string], Key, object>
56+
>get : <Key extends [id1: string, id2: string] | [id1: string] | []>(...key: Key) => GetResult<[id1: string, id2: string], Key, object>
5757
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5858
>id1 : string
5959
> : ^^^^^^

0 commit comments

Comments
 (0)