Skip to content

Commit 44e827b

Browse files
authored
Eliminate redundant or meaningless elaborations in type relations (#47738)
* Eliminate redundant or meaningless elaborations in type relations * Accept new baselines * Add resetErrorInfo (though, oddly, shouldn't be necessary) * Less aggressive reduction in second pass union/intersection checks * Accept new baselines * Restructure and back off a little bit more * Only cache union/intersection relations once * Accept new baselines * Properly cache identity relations, clean up error reporting * Move more logic to cached side of relation checks * Optimize and remove more redundant elaborations * Accept new baselines * Remove unnecessary error state capture * More optimizing * Cache isWeakType computation * Revert "Cache isWeakType computation" This reverts commit 25a71c4. * Address CR feedback * Accept new baselines
1 parent c3a0552 commit 44e827b

33 files changed

+442
-711
lines changed

src/compiler/checker.ts

Lines changed: 284 additions & 301 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticMessages.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,14 @@
871871
"category": "Error",
872872
"code": 1269
873873
},
874+
"Decorator function return type '{0}' is not assignable to type '{1}'.": {
875+
"category": "Error",
876+
"code": 1270
877+
},
878+
"Decorator function return type is '{0}' but is expected to be 'void' or 'any'.": {
879+
"category": "Error",
880+
"code": 1271
881+
},
874882

875883
"'with' statements are not allowed in an async function block.": {
876884
"category": "Error",

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5175,6 +5175,8 @@ namespace ts {
51755175
ESSymbolLike = ESSymbol | UniqueESSymbol,
51765176
VoidLike = Void | Undefined,
51775177
/* @internal */
5178+
DefinitelyNonNullable = StringLike | NumberLike | BigIntLike | BooleanLike | EnumLike | ESSymbolLike | Object | NonPrimitive,
5179+
/* @internal */
51785180
DisjointDomains = NonPrimitive | StringLike | NumberLike | BigIntLike | BooleanLike | ESSymbolLike | VoidLike | Null,
51795181
UnionOrIntersection = Union | Intersection,
51805182
StructuredType = Object | Union | Intersection,

tests/baselines/reference/bigintWithLib.errors.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ tests/cases/compiler/bigintWithLib.ts(31,35): error TS2769: No overload matches
2020
Argument of type 'number[]' is not assignable to parameter of type 'Iterable<bigint>'.
2121
Overload 3 of 3, '(buffer: ArrayBufferLike, byteOffset?: number, length?: number): BigUint64Array', gave the following error.
2222
Argument of type 'number[]' is not assignable to parameter of type 'ArrayBufferLike'.
23-
Type 'number[]' is not assignable to type 'SharedArrayBuffer'.
2423
tests/cases/compiler/bigintWithLib.ts(36,13): error TS2540: Cannot assign to 'length' because it is a read-only property.
2524
tests/cases/compiler/bigintWithLib.ts(43,25): error TS2345: Argument of type 'number' is not assignable to parameter of type 'bigint'.
2625
tests/cases/compiler/bigintWithLib.ts(46,26): error TS2345: Argument of type 'number' is not assignable to parameter of type 'bigint'.
@@ -84,7 +83,6 @@ tests/cases/compiler/bigintWithLib.ts(46,26): error TS2345: Argument of type 'nu
8483
!!! error TS2769: Argument of type 'number[]' is not assignable to parameter of type 'Iterable<bigint>'.
8584
!!! error TS2769: Overload 3 of 3, '(buffer: ArrayBufferLike, byteOffset?: number, length?: number): BigUint64Array', gave the following error.
8685
!!! error TS2769: Argument of type 'number[]' is not assignable to parameter of type 'ArrayBufferLike'.
87-
!!! error TS2769: Type 'number[]' is not assignable to type 'SharedArrayBuffer'.
8886
bigUintArray = new BigUint64Array(new ArrayBuffer(80));
8987
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8);
9088
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3);

tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/jsdoc/0.js(5,3): error TS2322: Type 'number' is not assignable to type 'string | undefined'.
1+
tests/cases/conformance/jsdoc/0.js(5,3): error TS2322: Type 'number' is not assignable to type 'string'.
22
tests/cases/conformance/jsdoc/0.js(8,7): error TS2322: Type 'string' is not assignable to type 'number'.
33
tests/cases/conformance/jsdoc/0.js(11,20): error TS2322: Type 'string' is not assignable to type 'number'.
44
tests/cases/conformance/jsdoc/0.js(13,15): error TS2322: Type 'string' is not assignable to type 'number'.
@@ -15,7 +15,7 @@ tests/cases/conformance/jsdoc/0.js(22,22): error TS2345: Argument of type 'strin
1515
/** @type {string|undefined} */
1616
bar: 42,
1717
~~~~~~~
18-
!!! error TS2322: Type 'number' is not assignable to type 'string | undefined'.
18+
!!! error TS2322: Type 'number' is not assignable to type 'string'.
1919
/** @type {function(number): number} */
2020
method1(n1) {
2121
return "42";

tests/baselines/reference/checkJsxChildrenProperty4.errors.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
tests/cases/conformance/jsx/file.tsx(24,28): error TS2551: Property 'NAme' does not exist on type 'IUser'. Did you mean 'Name'?
22
tests/cases/conformance/jsx/file.tsx(36,15): error TS2322: Type '(user: IUser) => Element' is not assignable to type 'boolean | any[] | ReactChild'.
3-
Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement<any>': type, props
43
tests/cases/conformance/jsx/file.tsx(39,15): error TS2322: Type '(user: IUser) => Element' is not assignable to type 'boolean | any[] | ReactChild'.
5-
Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement<any>': type, props
64

75

86
==== tests/cases/conformance/jsx/file.tsx (3 errors) ====
@@ -51,7 +49,6 @@ tests/cases/conformance/jsx/file.tsx(39,15): error TS2322: Type '(user: IUser) =
5149
) }
5250
~~~~~~~~~~~~~
5351
!!! error TS2322: Type '(user: IUser) => Element' is not assignable to type 'boolean | any[] | ReactChild'.
54-
!!! error TS2322: Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement<any>': type, props
5552
!!! related TS6212 tests/cases/conformance/jsx/file.tsx:36:15: Did you mean to call this expression?
5653
{ user => (
5754
~~~~~~~~~
@@ -60,7 +57,6 @@ tests/cases/conformance/jsx/file.tsx(39,15): error TS2322: Type '(user: IUser) =
6057
) }
6158
~~~~~~~~~~~~~
6259
!!! error TS2322: Type '(user: IUser) => Element' is not assignable to type 'boolean | any[] | ReactChild'.
63-
!!! error TS2322: Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement<any>': type, props
6460
!!! related TS6212 tests/cases/conformance/jsx/file.tsx:39:15: Did you mean to call this expression?
6561
</FetchUser>
6662
);

0 commit comments

Comments
 (0)