Skip to content

Commit 7c99086

Browse files
authored
fix(39524): convert access property suggestion to string (microsoft#39527)
1 parent 03c79d7 commit 7c99086

6 files changed

+54
-2
lines changed

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4757,7 +4757,7 @@ namespace ts {
47574757
if (isPropertyAccessExpression(expr)) {
47584758
const baseStr = tryGetPropertyAccessOrIdentifierToString(expr.expression);
47594759
if (baseStr !== undefined) {
4760-
return baseStr + "." + expr.name;
4760+
return baseStr + "." + entityNameToString(expr.name);
47614761
}
47624762
}
47634763
else if (isIdentifier(expr)) {

tests/baselines/reference/noImplicitAnyStringIndexerOnObject.errors.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(76,1): error TS7053:
3535
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; }'.
3636
Property '[StrEnum.b]' does not exist on type '{ a: number; }'.
3737
tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(93,5): error TS2538: Type 'Dog' cannot be used as an index type.
38+
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'?
3839

3940

40-
==== tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts (30 errors) ====
41+
==== tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts (31 errors) ====
4142
var a = {}["hello"];
4243
~~~~~~~~~~~
4344
!!! error TS7053: Element implicitly has an 'any' type because expression of type '"hello"' can't be used to index type '{}'.
@@ -198,4 +199,12 @@ tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(93,5): error TS2538:
198199
map[rover] = "Rover";
199200
~~~~~
200201
!!! error TS2538: Type 'Dog' cannot be used as an index type.
202+
203+
interface I {
204+
prop: MyMap<string, string>
205+
}
206+
declare const m: I;
207+
m.prop['a'];
208+
~~~~~~~~~~~
209+
!!! 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'?
201210

tests/baselines/reference/noImplicitAnyStringIndexerOnObject.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ let rover: Dog = { bark() {} };
9292

9393
declare let map: MyMap<Dog, string>;
9494
map[rover] = "Rover";
95+
96+
interface I {
97+
prop: MyMap<string, string>
98+
}
99+
declare const m: I;
100+
m.prop['a'];
95101

96102

97103
//// [noImplicitAnyStringIndexerOnObject.js]
@@ -168,3 +174,4 @@ var strEnumKey;
168174
o[strEnumKey];
169175
var rover = { bark: function () { } };
170176
map[rover] = "Rover";
177+
m.prop['a'];

tests/baselines/reference/noImplicitAnyStringIndexerOnObject.symbols

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,19 @@ map[rover] = "Rover";
277277
>map : Symbol(map, Decl(noImplicitAnyStringIndexerOnObject.ts, 91, 11))
278278
>rover : Symbol(rover, Decl(noImplicitAnyStringIndexerOnObject.ts, 89, 3))
279279

280+
interface I {
281+
>I : Symbol(I, Decl(noImplicitAnyStringIndexerOnObject.ts, 92, 21))
282+
283+
prop: MyMap<string, string>
284+
>prop : Symbol(I.prop, Decl(noImplicitAnyStringIndexerOnObject.ts, 94, 13))
285+
>MyMap : Symbol(MyMap, Decl(noImplicitAnyStringIndexerOnObject.ts, 80, 14))
286+
}
287+
declare const m: I;
288+
>m : Symbol(m, Decl(noImplicitAnyStringIndexerOnObject.ts, 97, 13))
289+
>I : Symbol(I, Decl(noImplicitAnyStringIndexerOnObject.ts, 92, 21))
290+
291+
m.prop['a'];
292+
>m.prop : Symbol(I.prop, Decl(noImplicitAnyStringIndexerOnObject.ts, 94, 13))
293+
>m : Symbol(m, Decl(noImplicitAnyStringIndexerOnObject.ts, 97, 13))
294+
>prop : Symbol(I.prop, Decl(noImplicitAnyStringIndexerOnObject.ts, 94, 13))
295+

tests/baselines/reference/noImplicitAnyStringIndexerOnObject.types

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,17 @@ map[rover] = "Rover";
418418
>rover : Dog
419419
>"Rover" : "Rover"
420420

421+
interface I {
422+
prop: MyMap<string, string>
423+
>prop : MyMap<string, string>
424+
}
425+
declare const m: I;
426+
>m : I
427+
428+
m.prop['a'];
429+
>m.prop['a'] : any
430+
>m.prop : MyMap<string, string>
431+
>m : I
432+
>prop : MyMap<string, string>
433+
>'a' : "a"
434+

tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,9 @@ let rover: Dog = { bark() {} };
9393

9494
declare let map: MyMap<Dog, string>;
9595
map[rover] = "Rover";
96+
97+
interface I {
98+
prop: MyMap<string, string>
99+
}
100+
declare const m: I;
101+
m.prop['a'];

0 commit comments

Comments
 (0)