diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index edbe017be7c..173bcc555fe 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5463,7 +5463,7 @@ namespace ts { return `__@${type.symbol.name}@${getSymbolId(type.symbol)}`; } if (type.flags & TypeFlags.StringOrNumberLiteral) { - return escapeIdentifier("" + (type).value); + return "" + (type).value; } } @@ -7686,8 +7686,8 @@ namespace ts { function getPropertyTypeForIndexType(objectType: Type, indexType: Type, accessNode: ElementAccessExpression | IndexedAccessTypeNode, cacheSymbol: boolean) { const accessExpression = accessNode && accessNode.kind === SyntaxKind.ElementAccessExpression ? accessNode : undefined; - const propName = indexType.flags & TypeFlags.StringOrNumberLiteral ? - "" + (indexType).value : + const propName = indexType.flags & TypeFlags.StringOrNumberLiteralOrUnique ? + getLateBoundNameFromType(indexType) : accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ? getPropertyNameForKnownSymbolName(((accessExpression.argumentExpression).name).text) : undefined; diff --git a/tests/baselines/reference/dynamicNames.js b/tests/baselines/reference/dynamicNames.js index 4f79d7df0fc..41b57f57908 100644 --- a/tests/baselines/reference/dynamicNames.js +++ b/tests/baselines/reference/dynamicNames.js @@ -123,6 +123,11 @@ export const o1 = { [s2]: true }; +// check element access types +export const o1_c4 = o1[c4]; +export const o1_c5 = o1[c5]; +export const o1_s2 = o1[s2]; + export const o2: T0 = o1; //// [module.js] @@ -174,6 +179,10 @@ exports.o1 = { [exports.c5]: "a", [exports.s2]: true }; +// check element access types +exports.o1_c4 = exports.o1[exports.c4]; +exports.o1_c5 = exports.o1[exports.c5]; +exports.o1_s2 = exports.o1[exports.s2]; exports.o2 = exports.o1; @@ -208,4 +217,7 @@ export declare const o1: { [c5]: string; [s2]: boolean; }; +export declare const o1_c4: number; +export declare const o1_c5: string; +export declare const o1_s2: boolean; export declare const o2: T0; diff --git a/tests/baselines/reference/dynamicNames.symbols b/tests/baselines/reference/dynamicNames.symbols index 5d917aa1e6f..056c77843fe 100644 --- a/tests/baselines/reference/dynamicNames.symbols +++ b/tests/baselines/reference/dynamicNames.symbols @@ -404,8 +404,24 @@ export const o1 = { }; +// check element access types +export const o1_c4 = o1[c4]; +>o1_c4 : Symbol(o1_c4, Decl(main.ts, 101, 12)) +>o1 : Symbol(o1, Decl(main.ts, 94, 12)) +>c4 : Symbol(c4, Decl(main.ts, 27, 12)) + +export const o1_c5 = o1[c5]; +>o1_c5 : Symbol(o1_c5, Decl(main.ts, 102, 12)) +>o1 : Symbol(o1, Decl(main.ts, 94, 12)) +>c5 : Symbol(c5, Decl(main.ts, 28, 12)) + +export const o1_s2 = o1[s2]; +>o1_s2 : Symbol(o1_s2, Decl(main.ts, 103, 12)) +>o1 : Symbol(o1, Decl(main.ts, 94, 12)) +>s2 : Symbol(s2, Decl(main.ts, 29, 12)) + export const o2: T0 = o1; ->o2 : Symbol(o2, Decl(main.ts, 100, 12)) +>o2 : Symbol(o2, Decl(main.ts, 105, 12)) >T0 : Symbol(T0, Decl(main.ts, 0, 20)) >o1 : Symbol(o1, Decl(main.ts, 94, 12)) diff --git a/tests/baselines/reference/dynamicNames.types b/tests/baselines/reference/dynamicNames.types index af5e34d4404..058585be7da 100644 --- a/tests/baselines/reference/dynamicNames.types +++ b/tests/baselines/reference/dynamicNames.types @@ -476,6 +476,25 @@ export const o1 = { }; +// check element access types +export const o1_c4 = o1[c4]; +>o1_c4 : number +>o1[c4] : number +>o1 : { [c4]: number; [c5]: string; [s2]: boolean; } +>c4 : "a" + +export const o1_c5 = o1[c5]; +>o1_c5 : string +>o1[c5] : string +>o1 : { [c4]: number; [c5]: string; [s2]: boolean; } +>c5 : 1 + +export const o1_s2 = o1[s2]; +>o1_s2 : boolean +>o1[s2] : boolean +>o1 : { [c4]: number; [c5]: string; [s2]: boolean; } +>s2 : typeof s0 + export const o2: T0 = o1; >o2 : T0 >T0 : T0 diff --git a/tests/cases/compiler/dynamicNames.ts b/tests/cases/compiler/dynamicNames.ts index e8db8fe7404..3bf663892a7 100644 --- a/tests/cases/compiler/dynamicNames.ts +++ b/tests/cases/compiler/dynamicNames.ts @@ -125,4 +125,9 @@ export const o1 = { [s2]: true }; +// check element access types +export const o1_c4 = o1[c4]; +export const o1_c5 = o1[c5]; +export const o1_s2 = o1[s2]; + export const o2: T0 = o1; \ No newline at end of file