Skip to content

fix(39524): Diagnostic message contains a stray "[object Object]" #39527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4755,7 +4755,7 @@ namespace ts {
if (isPropertyAccessExpression(expr)) {
const baseStr = tryGetPropertyAccessOrIdentifierToString(expr.expression);
if (baseStr !== undefined) {
return baseStr + "." + expr.name;
return baseStr + "." + entityNameToString(expr.name);
}
}
else if (isIdentifier(expr)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(76,1): error TS7053:
tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(81,1): error TS7053: Element implicitly has an 'any' type because expression of type 'StrEnum' can't be used to index type '{ a: number; }'.
Property '[StrEnum.b]' does not exist on type '{ a: number; }'.
tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(93,5): error TS2538: Type 'Dog' cannot be used as an index type.
tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(99,1): error TS7052: Element implicitly has an 'any' type because type 'MyMap<string, string>' has no index signature. Did you mean to call 'm.prop.get'?


==== tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts (30 errors) ====
==== tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts (31 errors) ====
var a = {}["hello"];
~~~~~~~~~~~
!!! error TS7053: Element implicitly has an 'any' type because expression of type '"hello"' can't be used to index type '{}'.
Expand Down Expand Up @@ -198,4 +199,12 @@ tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(93,5): error TS2538:
map[rover] = "Rover";
~~~~~
!!! error TS2538: Type 'Dog' cannot be used as an index type.

interface I {
prop: MyMap<string, string>
}
declare const m: I;
m.prop['a'];
~~~~~~~~~~~
!!! error TS7052: Element implicitly has an 'any' type because type 'MyMap<string, string>' has no index signature. Did you mean to call 'm.prop.get'?

Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ let rover: Dog = { bark() {} };

declare let map: MyMap<Dog, string>;
map[rover] = "Rover";

interface I {
prop: MyMap<string, string>
}
declare const m: I;
m.prop['a'];


//// [noImplicitAnyStringIndexerOnObject.js]
Expand Down Expand Up @@ -168,3 +174,4 @@ var strEnumKey;
o[strEnumKey];
var rover = { bark: function () { } };
map[rover] = "Rover";
m.prop['a'];
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,19 @@ map[rover] = "Rover";
>map : Symbol(map, Decl(noImplicitAnyStringIndexerOnObject.ts, 91, 11))
>rover : Symbol(rover, Decl(noImplicitAnyStringIndexerOnObject.ts, 89, 3))

interface I {
>I : Symbol(I, Decl(noImplicitAnyStringIndexerOnObject.ts, 92, 21))

prop: MyMap<string, string>
>prop : Symbol(I.prop, Decl(noImplicitAnyStringIndexerOnObject.ts, 94, 13))
>MyMap : Symbol(MyMap, Decl(noImplicitAnyStringIndexerOnObject.ts, 80, 14))
}
declare const m: I;
>m : Symbol(m, Decl(noImplicitAnyStringIndexerOnObject.ts, 97, 13))
>I : Symbol(I, Decl(noImplicitAnyStringIndexerOnObject.ts, 92, 21))

m.prop['a'];
>m.prop : Symbol(I.prop, Decl(noImplicitAnyStringIndexerOnObject.ts, 94, 13))
>m : Symbol(m, Decl(noImplicitAnyStringIndexerOnObject.ts, 97, 13))
>prop : Symbol(I.prop, Decl(noImplicitAnyStringIndexerOnObject.ts, 94, 13))

14 changes: 14 additions & 0 deletions tests/baselines/reference/noImplicitAnyStringIndexerOnObject.types
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,17 @@ map[rover] = "Rover";
>rover : Dog
>"Rover" : "Rover"

interface I {
prop: MyMap<string, string>
>prop : MyMap<string, string>
}
declare const m: I;
>m : I

m.prop['a'];
>m.prop['a'] : any
>m.prop : MyMap<string, string>
>m : I
>prop : MyMap<string, string>
>'a' : "a"

6 changes: 6 additions & 0 deletions tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,9 @@ let rover: Dog = { bark() {} };

declare let map: MyMap<Dog, string>;
map[rover] = "Rover";

interface I {
prop: MyMap<string, string>
}
declare const m: I;
m.prop['a'];