Skip to content

Commit 652c96c

Browse files
authored
Fix circularity errors in intra-binding-pattern references (#59183)
1 parent 0314372 commit 652c96c

File tree

42 files changed

+598
-411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+598
-411
lines changed

src/compiler/checker.ts

Lines changed: 84 additions & 81 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,10 +2680,6 @@
26802680
"category": "Error",
26812681
"code": 2524
26822682
},
2683-
"Initializer provides no value for this binding element and the binding element has no default value.": {
2684-
"category": "Error",
2685-
"code": 2525
2686-
},
26872683
"A 'this' type is available only in a non-static member of a class or interface.": {
26882684
"category": "Error",
26892685
"code": 2526

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6697,7 +6697,7 @@ export const enum AccessFlags {
66976697
NoIndexSignatures = 1 << 1,
66986698
Writing = 1 << 2,
66996699
CacheSymbol = 1 << 3,
6700-
NoTupleBoundsCheck = 1 << 4,
6700+
AllowMissing = 1 << 4,
67016701
ExpressionPosition = 1 << 5,
67026702
ReportDeprecated = 1 << 6,
67036703
SuppressNoImplicitAnyError = 1 << 7,

tests/baselines/reference/checkDestructuringShorthandAssigment.types

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ function Test({ b = '' } = {}) {}
99
> : ^^^^^^
1010
>'' : ""
1111
> : ^^
12-
>{} : { b?: string; }
13-
> : ^^^^^^^^^^^^^^^
12+
>{} : {}
13+
> : ^^
1414

1515
Test(({ b = '5' } = {}));
1616
>Test(({ b = '5' } = {})) : void
1717
> : ^^^^
1818
>Test : ({ b }?: { b?: string; }) => void
1919
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
20-
>({ b = '5' } = {}) : { b?: any; }
21-
> : ^^^^^^^^^^^^
22-
>{ b = '5' } = {} : { b?: any; }
23-
> : ^^^^^^^^^^^^
20+
>({ b = '5' } = {}) : {}
21+
> : ^^
22+
>{ b = '5' } = {} : {}
23+
> : ^^
2424
>{ b = '5' } : { b?: any; }
2525
> : ^^^^^^^^^^^^
2626
>b : any
2727
> : ^^^
2828
>'5' : "5"
2929
> : ^^^
30-
>{} : { b?: any; }
31-
> : ^^^^^^^^^^^^
30+
>{} : {}
31+
> : ^^
3232

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
checkDestructuringShorthandAssigment2.ts(4,7): error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
21
checkDestructuringShorthandAssigment2.ts(4,27): error TS2353: Object literal may only specify known properties, and '[k]' does not exist in type '{ x: any; }'.
32

43

5-
==== checkDestructuringShorthandAssigment2.ts (2 errors) ====
4+
==== checkDestructuringShorthandAssigment2.ts (1 errors) ====
65
// GH #38175 -- should not crash while checking
76

87
let o: any, k: any;
98
let { x } = { x: 1, ...o, [k]: 1 };
10-
~
11-
!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
129
~~~
1310
!!! error TS2353: Object literal may only specify known properties, and '[k]' does not exist in type '{ x: any; }'.
1411

tests/baselines/reference/circularReferenceInReturnType2.types

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ type Something = { foo: number };
104104

105105
// inference fails here, but ideally should not
106106
const A = object<Something>()({
107-
>A : ObjectType<Something>
108-
> : ^^^^^^^^^^^^^^^^^^^^^
107+
>A : any
108+
> : ^^^
109109
>object<Something>()({ name: "A", fields: () => ({ a: field({ type: A, resolve() { return { foo: 100, }; }, }), }),}) : ObjectType<Something>
110110
> : ^^^^^^^^^^^^^^^^^^^^^
111111
>object<Something>() : <Fields extends { [Key in keyof Fields]: Field<Something, Key & string>; }>(config: { name: string; fields: Fields | (() => Fields); }) => ObjectType<Something>
@@ -138,14 +138,14 @@ const A = object<Something>()({
138138
> : ^^^^^^^^^^^^^^^^^^^^^
139139
>field : <Source, Type extends ObjectType<any>, Key extends string>(field: FieldFuncArgs<Source, Type>) => Field<Source, Key>
140140
> : ^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^^^^
141-
>{ type: A, resolve() { return { foo: 100, }; }, } : { type: ObjectType<Something>; resolve(): { foo: number; }; }
142-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
141+
>{ type: A, resolve() { return { foo: 100, }; }, } : { type: any; resolve(): { foo: number; }; }
142+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
143143

144144
type: A,
145-
>type : ObjectType<Something>
146-
> : ^^^^^^^^^^^^^^^^^^^^^
147-
>A : ObjectType<Something>
148-
> : ^^^^^^^^^^^^^^^^^^^^^
145+
>type : any
146+
> : ^^^
147+
>A : any
148+
> : ^^^
149149

150150
resolve() {
151151
>resolve : () => { foo: number; }

tests/baselines/reference/contextualTypeForInitalizedVariablesFiltersUndefined.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const fInferred = ({ a = 0 } = {}) => a;
1010
> : ^^^^^^
1111
>0 : 0
1212
> : ^
13-
>{} : { a?: number | undefined; }
14-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
>{} : {}
14+
> : ^^
1515
>a : number
1616
> : ^^^^^^
1717

tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ try {
5353
> : ^^^^^^
5454
>1 : 1
5555
> : ^
56-
>{ } : { e?: number | undefined; }
57-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
56+
>{ } : {}
57+
> : ^^
5858

5959
} catch {
6060
console.error("error");

tests/baselines/reference/declarationsAndAssignments.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ declarationsAndAssignments.ts(63,13): error TS2493: Tuple type '[number]' of len
1111
declarationsAndAssignments.ts(63,16): error TS2493: Tuple type '[number]' of length '1' has no element at index '2'.
1212
declarationsAndAssignments.ts(67,9): error TS2461: Type '{}' is not an array type.
1313
declarationsAndAssignments.ts(68,9): error TS2461: Type '{ 0: number; 1: number; }' is not an array type.
14-
declarationsAndAssignments.ts(73,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
15-
declarationsAndAssignments.ts(73,14): error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
14+
declarationsAndAssignments.ts(73,11): error TS2339: Property 'a' does not exist on type '{}'.
15+
declarationsAndAssignments.ts(73,14): error TS2339: Property 'b' does not exist on type '{}'.
1616
declarationsAndAssignments.ts(74,11): error TS2339: Property 'a' does not exist on type 'undefined[]'.
1717
declarationsAndAssignments.ts(74,14): error TS2339: Property 'b' does not exist on type 'undefined[]'.
1818
declarationsAndAssignments.ts(106,17): error TS2741: Property 'x' is missing in type '{ y: false; }' but required in type '{ x: any; y?: boolean; }'.
@@ -122,9 +122,9 @@ declarationsAndAssignments.ts(138,9): error TS2322: Type 'number' is not assigna
122122
function f10() {
123123
var { a, b } = {}; // Error
124124
~
125-
!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
125+
!!! error TS2339: Property 'a' does not exist on type '{}'.
126126
~
127-
!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
127+
!!! error TS2339: Property 'b' does not exist on type '{}'.
128128
var { a, b } = []; // Error
129129
~
130130
!!! error TS2339: Property 'a' does not exist on type 'undefined[]'.

tests/baselines/reference/declarationsAndAssignments.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ function f10() {
486486
> : ^^^
487487
>b : any
488488
> : ^^^
489-
>{} : { a: any; b: any; }
490-
> : ^^^^^^^^^^^^^^^^^^^
489+
>{} : {}
490+
> : ^^
491491

492492
var { a, b } = []; // Error
493493
>a : any

tests/baselines/reference/destructuredLateBoundNameHasCorrectTypes.errors.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
destructuredLateBoundNameHasCorrectTypes.ts(11,21): error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
1+
destructuredLateBoundNameHasCorrectTypes.ts(11,8): error TS2339: Property 'prop2' does not exist on type '{ prop: string; }'.
22
destructuredLateBoundNameHasCorrectTypes.ts(11,37): error TS2353: Object literal may only specify known properties, and 'prop' does not exist in type '{ prop2: any; }'.
33

44

@@ -14,8 +14,8 @@ destructuredLateBoundNameHasCorrectTypes.ts(11,37): error TS2353: Object literal
1414
const notPresent = "prop2";
1515

1616
let { [notPresent]: computed2 } = { prop: "b" };
17-
~~~~~~~~~
18-
!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
17+
~~~~~~~~~~
18+
!!! error TS2339: Property 'prop2' does not exist on type '{ prop: string; }'.
1919
~~~~
2020
!!! error TS2353: Object literal may only specify known properties, and 'prop' does not exist in type '{ prop2: any; }'.
2121

tests/baselines/reference/destructuredLateBoundNameHasCorrectTypes.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ let { [notPresent]: computed2 } = { prop: "b" };
5454
> : ^^^^^^^
5555
>computed2 : any
5656
> : ^^^
57-
>{ prop: "b" } : { prop: string; prop2: any; }
58-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
57+
>{ prop: "b" } : { prop: string; }
58+
> : ^^^^^^^^^^^^^^^^^
5959
>prop : string
6060
> : ^^^^^^
6161
>"b" : "b"

tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.types

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ const [c, d = c, e = e] = [1]; // error for e = e
3030
> : ^
3131

3232
const [f, g = f, h = i, i = f] = [1]; // error for h = i
33-
>f : any
34-
> : ^^^
35-
>g : any
36-
> : ^^^
37-
>f : any
38-
> : ^^^
39-
>h : any
40-
> : ^^^
41-
>i : any
42-
> : ^^^
43-
>i : any
44-
> : ^^^
45-
>f : any
46-
> : ^^^
33+
>f : number
34+
> : ^^^^^^
35+
>g : number
36+
> : ^^^^^^
37+
>f : number
38+
> : ^^^^^^
39+
>h : number
40+
> : ^^^^^^
41+
>i : number
42+
> : ^^^^^^
43+
>i : number
44+
> : ^^^^^^
45+
>f : number
46+
> : ^^^^^^
4747
>[1] : [number]
4848
> : ^^^^^^^^
4949
>1 : 1
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
destructuringFromUnionSpread.ts(5,9): error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
1+
destructuringFromUnionSpread.ts(5,9): error TS2339: Property 'a' does not exist on type '{ a: string; } | { b: number; }'.
22

33

44
==== destructuringFromUnionSpread.ts (1 errors) ====
@@ -8,5 +8,5 @@ destructuringFromUnionSpread.ts(5,9): error TS2525: Initializer provides no valu
88
declare const x: A | B;
99
const { a } = { ...x } // error
1010
~
11-
!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
11+
!!! error TS2339: Property 'a' does not exist on type '{ a: string; } | { b: number; }'.
1212

tests/baselines/reference/destructuringFromUnionSpread.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ declare const x: A | B;
1616
const { a } = { ...x } // error
1717
>a : any
1818
> : ^^^
19-
>{ ...x } : { a: any; } | { a: any; b: number; }
20-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
19+
>{ ...x } : { a: string; } | { b: number; }
20+
> : ^^^^^ ^^^^^^^^^^^ ^^^
2121
>x : A | B
2222
> : ^^^^^
2323

tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ destructuringObjectBindingPatternAndAssignment3.ts(2,7): error TS1005: ',' expec
22
destructuringObjectBindingPatternAndAssignment3.ts(3,5): error TS2322: Type '{ i: number; }' is not assignable to type 'string | number'.
33
destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2339: Property 'i' does not exist on type 'string | number'.
44
destructuringObjectBindingPatternAndAssignment3.ts(4,6): error TS2339: Property 'i1' does not exist on type 'string | number | {}'.
5-
destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
65
destructuringObjectBindingPatternAndAssignment3.ts(5,21): error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'.
76
destructuringObjectBindingPatternAndAssignment3.ts(6,7): error TS1005: ':' expected.
87
destructuringObjectBindingPatternAndAssignment3.ts(6,15): error TS1005: ':' expected.
98
destructuringObjectBindingPatternAndAssignment3.ts(7,12): error TS1005: ':' expected.
109

1110

12-
==== destructuringObjectBindingPatternAndAssignment3.ts (9 errors) ====
11+
==== destructuringObjectBindingPatternAndAssignment3.ts (8 errors) ====
1312
// Error
1413
var {h?} = { h?: 1 };
1514
~
@@ -23,8 +22,6 @@ destructuringObjectBindingPatternAndAssignment3.ts(7,12): error TS1005: ':' expe
2322
~~
2423
!!! error TS2339: Property 'i1' does not exist on type 'string | number | {}'.
2524
var { f2: {f21} = { f212: "string" } }: any = undefined;
26-
~~~
27-
!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
2825
~~~~
2926
!!! error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'.
3027
var {1} = { 1 };

tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ var { f2: {f21} = { f212: "string" } }: any = undefined;
3737
> : ^^^
3838
>f21 : any
3939
> : ^^^
40-
>{ f212: "string" } : { f212: string; f21: any; }
41-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
40+
>{ f212: "string" } : { f212: string; }
41+
> : ^^^^^^^^^^^^^^^^^
4242
>f212 : string
4343
> : ^^^^^^
4444
>"string" : "string"

tests/baselines/reference/destructuringObjectBindingPatternAndAssignment9SiblingInitializer.types

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function f1() {
1313
> : ^^^^^^
1414
>a1 : number
1515
> : ^^^^^^
16-
>{ a1: 1 } : { a1: number; b1?: number; }
17-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
>{ a1: 1 } : { a1: number; }
17+
> : ^^^^^^^^^^^^^^^
1818
>a1 : number
1919
> : ^^^^^^
2020
>1 : 1
@@ -31,8 +31,8 @@ function f1() {
3131
> : ^
3232
>a2 : number
3333
> : ^^^^^^
34-
>{ a2: 1 } : { a2: number; b2?: number; }
35-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34+
>{ a2: 1 } : { a2: number; }
35+
> : ^^^^^^^^^^^^^^^
3636
>a2 : number
3737
> : ^^^^^^
3838
>1 : 1
@@ -51,8 +51,8 @@ function f2() {
5151
> : ^^^^^^
5252
>a1 : string
5353
> : ^^^^^^
54-
>{ a1: 'hi' } : { a1: string; b1?: string; }
55-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54+
>{ a1: 'hi' } : { a1: string; }
55+
> : ^^^^^^^^^^^^^^^
5656
>a1 : string
5757
> : ^^^^^^
5858
>'hi' : "hi"
@@ -69,8 +69,8 @@ function f2() {
6969
> : ^^^^^^
7070
>'!' : "!"
7171
> : ^^^
72-
>{ a2: 'hi' } : { a2: string; b2?: string; }
73-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
72+
>{ a2: 'hi' } : { a2: string; }
73+
> : ^^^^^^^^^^^^^^^
7474
>a2 : string
7575
> : ^^^^^^
7676
>'hi' : "hi"

tests/baselines/reference/destructuringSpread.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
destructuringSpread.ts(16,21): error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
1+
destructuringSpread.ts(16,21): error TS2339: Property 'g' does not exist on type '{ f: number; e: number; d: number; c: number; }'.
22

33

44
==== destructuringSpread.ts (1 errors) ====
@@ -19,7 +19,7 @@ destructuringSpread.ts(16,21): error TS2525: Initializer provides no value for t
1919

2020
const { c, d, e, f, g } = {
2121
~
22-
!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
22+
!!! error TS2339: Property 'g' does not exist on type '{ f: number; e: number; d: number; c: number; }'.
2323
...{
2424
...{
2525
...{

tests/baselines/reference/destructuringSpread.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ const { c, d, e, f, g } = {
7878
> : ^^^^^^
7979
>g : any
8080
> : ^^^
81-
>{ ...{ ...{ ...{ c: 0, }, d: 0 }, e: 0 }, f: 0} : { f: number; g: any; e: number; d: number; c: number; }
82-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
81+
>{ ...{ ...{ ...{ c: 0, }, d: 0 }, e: 0 }, f: 0} : { f: number; e: number; d: number; c: number; }
82+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8383

8484
...{
8585
>{ ...{ ...{ c: 0, }, d: 0 }, e: 0 } : { e: number; d: number; c: number; }

0 commit comments

Comments
 (0)