Skip to content

Commit 7611579

Browse files
committed
Small fix in getObjectLiteralIndexInfo
Fixes microsoft#38175
1 parent f560560 commit 7611579

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23470,8 +23470,8 @@ namespace ts {
2347023470

2347123471
function getObjectLiteralIndexInfo(node: ObjectLiteralExpression, offset: number, properties: Symbol[], kind: IndexKind): IndexInfo {
2347223472
const propTypes: Type[] = [];
23473-
for (let i = 0; i < properties.length; i++) {
23474-
if (kind === IndexKind.String || isNumericName(node.properties[i + offset].name!)) {
23473+
for (let i = offset; i < properties.length; i++) {
23474+
if (kind === IndexKind.String || isNumericName(node.properties[i].name!)) {
2347523475
propTypes.push(getTypeOfSymbol(properties[i]));
2347623476
}
2347723477
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tests/cases/compiler/checkDestructuringShorthandAssigment2.ts(4,7): error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
2+
tests/cases/compiler/checkDestructuringShorthandAssigment2.ts(4,27): error TS2353: Object literal may only specify known properties, and '[k]' does not exist in type '{ x: any; }'.
3+
4+
5+
==== tests/cases/compiler/checkDestructuringShorthandAssigment2.ts (2 errors) ====
6+
// GH #38175 -- should not crash while checking
7+
8+
let o: any, k: any;
9+
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.
12+
~~~
13+
!!! error TS2353: Object literal may only specify known properties, and '[k]' does not exist in type '{ x: any; }'.
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/checkDestructuringShorthandAssigment2.ts ===
2+
// GH #38175 -- should not crash while checking
3+
4+
let o: any, k: any;
5+
>o : Symbol(o, Decl(checkDestructuringShorthandAssigment2.ts, 2, 3))
6+
>k : Symbol(k, Decl(checkDestructuringShorthandAssigment2.ts, 2, 11))
7+
8+
let { x } = { x: 1, ...o, [k]: 1 };
9+
>x : Symbol(x, Decl(checkDestructuringShorthandAssigment2.ts, 3, 5))
10+
>x : Symbol(x, Decl(checkDestructuringShorthandAssigment2.ts, 3, 13))
11+
>o : Symbol(o, Decl(checkDestructuringShorthandAssigment2.ts, 2, 3))
12+
>[k] : Symbol([k], Decl(checkDestructuringShorthandAssigment2.ts, 3, 25))
13+
>k : Symbol(k, Decl(checkDestructuringShorthandAssigment2.ts, 2, 11))
14+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/compiler/checkDestructuringShorthandAssigment2.ts ===
2+
// GH #38175 -- should not crash while checking
3+
4+
let o: any, k: any;
5+
>o : any
6+
>k : any
7+
8+
let { x } = { x: 1, ...o, [k]: 1 };
9+
>x : any
10+
>{ x: 1, ...o, [k]: 1 } : any
11+
>x : number
12+
>1 : 1
13+
>o : any
14+
>[k] : number
15+
>k : any
16+
>1 : 1
17+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @noEmit: true
2+
3+
// GH #38175 -- should not crash while checking
4+
5+
let o: any, k: any;
6+
let { x } = { x: 1, ...o, [k]: 1 };

0 commit comments

Comments
 (0)