Skip to content

Commit 23746af

Browse files
authoredSep 20, 2022
fix(50591): RangeError: Maximum call stack size exceeded (#50594)
1 parent 168186f commit 23746af

6 files changed

+92
-1
lines changed
 

‎src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23660,7 +23660,7 @@ namespace ts {
2366023660
}
2366123661
}
2366223662

23663-
if (hasOnlyExpressionInitializer(declaration)) {
23663+
if (hasOnlyExpressionInitializer(declaration) && isBlockScopedNameDeclaredBeforeUse(declaration, node.argumentExpression)) {
2366423664
const initializer = getEffectiveInitializer(declaration);
2366523665
return initializer && tryGetNameFromType(getTypeOfExpression(initializer));
2366623666
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests/cases/compiler/typeGuardNarrowsIndexedAccessOfKnownProperty10.ts(5,6): error TS2448: Block-scoped variable 'id' used before its declaration.
2+
3+
4+
==== tests/cases/compiler/typeGuardNarrowsIndexedAccessOfKnownProperty10.ts (1 errors) ====
5+
interface Foo { bar: any; }
6+
const bar: { [id: string]: number } = {};
7+
8+
(foo: Foo) => {
9+
bar[id]++;
10+
~~
11+
!!! error TS2448: Block-scoped variable 'id' used before its declaration.
12+
!!! related TS2728 tests/cases/compiler/typeGuardNarrowsIndexedAccessOfKnownProperty10.ts:6:8: 'id' is declared here.
13+
const id = foo.bar;
14+
}
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [typeGuardNarrowsIndexedAccessOfKnownProperty10.ts]
2+
interface Foo { bar: any; }
3+
const bar: { [id: string]: number } = {};
4+
5+
(foo: Foo) => {
6+
bar[id]++;
7+
const id = foo.bar;
8+
}
9+
10+
11+
//// [typeGuardNarrowsIndexedAccessOfKnownProperty10.js]
12+
"use strict";
13+
var bar = {};
14+
(function (foo) {
15+
bar[id]++;
16+
var id = foo.bar;
17+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/compiler/typeGuardNarrowsIndexedAccessOfKnownProperty10.ts ===
2+
interface Foo { bar: any; }
3+
>Foo : Symbol(Foo, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty10.ts, 0, 0))
4+
>bar : Symbol(Foo.bar, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty10.ts, 0, 15))
5+
6+
const bar: { [id: string]: number } = {};
7+
>bar : Symbol(bar, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty10.ts, 1, 5))
8+
>id : Symbol(id, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty10.ts, 1, 14))
9+
10+
(foo: Foo) => {
11+
>foo : Symbol(foo, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty10.ts, 3, 1))
12+
>Foo : Symbol(Foo, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty10.ts, 0, 0))
13+
14+
bar[id]++;
15+
>bar : Symbol(bar, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty10.ts, 1, 5))
16+
>id : Symbol(id, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty10.ts, 5, 6))
17+
18+
const id = foo.bar;
19+
>id : Symbol(id, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty10.ts, 5, 6))
20+
>foo.bar : Symbol(Foo.bar, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty10.ts, 0, 15))
21+
>foo : Symbol(foo, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty10.ts, 3, 1))
22+
>bar : Symbol(Foo.bar, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty10.ts, 0, 15))
23+
}
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/compiler/typeGuardNarrowsIndexedAccessOfKnownProperty10.ts ===
2+
interface Foo { bar: any; }
3+
>bar : any
4+
5+
const bar: { [id: string]: number } = {};
6+
>bar : { [id: string]: number; }
7+
>id : string
8+
>{} : {}
9+
10+
(foo: Foo) => {
11+
>(foo: Foo) => { bar[id]++; const id = foo.bar;} : (foo: Foo) => void
12+
>foo : Foo
13+
14+
bar[id]++;
15+
>bar[id]++ : number
16+
>bar[id] : number
17+
>bar : { [id: string]: number; }
18+
>id : any
19+
20+
const id = foo.bar;
21+
>id : any
22+
>foo.bar : any
23+
>foo : Foo
24+
>bar : any
25+
}
26+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @strict: true
2+
3+
interface Foo { bar: any; }
4+
const bar: { [id: string]: number } = {};
5+
6+
(foo: Foo) => {
7+
bar[id]++;
8+
const id = foo.bar;
9+
}

0 commit comments

Comments
 (0)