Skip to content

Commit

Permalink
Add string fallback for number
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed Apr 17, 2018
1 parent 0a86b23 commit d965c33
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4176,7 +4176,7 @@ namespace ts {
const exprType = checkExpression((name as ComputedPropertyName).expression);
let indexerType: Type;
if (isTypeAssignableToKind(exprType, TypeFlags.NumberLike)) {
indexerType = getIndexTypeOfType(parentType, IndexKind.Number);
indexerType = getIndexTypeOfType(parentType, IndexKind.Number) || getIndexTypeOfType(parentType, IndexKind.String);
}
else if (isTypeAssignableToKind(exprType, TypeFlags.StringLike)) {
indexerType = getIndexTypeOfType(parentType, IndexKind.String);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(2,15): error TS7017: Element implicitly has an 'any' type because type '{ prop: string; }' has no index signature.
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(10,15): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(16,15): error TS7017: Element implicitly has an 'any' type because type '{ [idx: string]: string; }' has no index signature.


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

Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ void prop4;

let {[numed]: prop5} = strIndexed;
>numed : number
>prop5 : any
>prop5 : string
>strIndexed : { [idx: string]: string; }

void prop5;
>void prop5 : undefined
>prop5 : any
>prop5 : string

0 comments on commit d965c33

Please sign in to comment.