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

0 commit comments

Comments
 (0)