Skip to content

Commit d965c33

Browse files
committed
Add string fallback for number
1 parent 0a86b23 commit d965c33

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4176,7 +4176,7 @@ namespace ts {
41764176
const exprType = checkExpression((name as ComputedPropertyName).expression);
41774177
let indexerType: Type;
41784178
if (isTypeAssignableToKind(exprType, TypeFlags.NumberLike)) {
4179-
indexerType = getIndexTypeOfType(parentType, IndexKind.Number);
4179+
indexerType = getIndexTypeOfType(parentType, IndexKind.Number) || getIndexTypeOfType(parentType, IndexKind.String);
41804180
}
41814181
else if (isTypeAssignableToKind(exprType, TypeFlags.StringLike)) {
41824182
indexerType = getIndexTypeOfType(parentType, IndexKind.String);

tests/baselines/reference/lateBoundDestructuringImplicitAnyError.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(2,15): error TS7017: Element implicitly has an 'any' type because type '{ prop: string; }' has no index signature.
22
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(10,15): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.
3-
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(16,15): error TS7017: Element implicitly has an 'any' type because type '{ [idx: string]: string; }' has no index signature.
43

54

6-
==== tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts (3 errors) ====
5+
==== tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts (2 errors) ====
76
let named = "foo";
87
let {[named]: prop} = {prop: "foo"};
98
~~~~
@@ -24,7 +23,5 @@ tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(16,15): error TS7
2423
let {[named]: prop4} = strIndexed;
2524
void prop4;
2625
let {[numed]: prop5} = strIndexed;
27-
~~~~~
28-
!!! error TS7017: Element implicitly has an 'any' type because type '{ [idx: string]: string; }' has no index signature.
2926
void prop5;
3027

tests/baselines/reference/lateBoundDestructuringImplicitAnyError.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ void prop4;
5959

6060
let {[numed]: prop5} = strIndexed;
6161
>numed : number
62-
>prop5 : any
62+
>prop5 : string
6363
>strIndexed : { [idx: string]: string; }
6464

6565
void prop5;
6666
>void prop5 : undefined
67-
>prop5 : any
67+
>prop5 : string
6868

0 commit comments

Comments
 (0)