Skip to content

Commit 7e91485

Browse files
authored
Use value meaning for computed property name for visibility check (#49678)
* Test * Use value meaning for computed property name Fixes #49562
1 parent df21926 commit 7e91485

5 files changed

+58
-2
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43363,13 +43363,20 @@ namespace ts {
4336343363
if (!fileToDirective) {
4336443364
return undefined;
4336543365
}
43366+
// computed property name should use node as value
4336643367
// property access can only be used as values, or types when within an expression with type arguments inside a heritage clause
4336743368
// qualified names can only be used as types\namespaces
4336843369
// identifiers are treated as values only if they appear in type queries
43369-
let meaning = SymbolFlags.Type | SymbolFlags.Namespace;
43370-
if ((node.kind === SyntaxKind.Identifier && isInTypeQuery(node)) || (node.kind === SyntaxKind.PropertyAccessExpression && !isInHeritageClause(node))) {
43370+
let meaning;
43371+
if (node.parent.kind === SyntaxKind.ComputedPropertyName) {
4337143372
meaning = SymbolFlags.Value | SymbolFlags.ExportValue;
4337243373
}
43374+
else {
43375+
meaning = SymbolFlags.Type | SymbolFlags.Namespace;
43376+
if ((node.kind === SyntaxKind.Identifier && isInTypeQuery(node)) || (node.kind === SyntaxKind.PropertyAccessExpression && !isInHeritageClause(node))) {
43377+
meaning = SymbolFlags.Value | SymbolFlags.ExportValue;
43378+
}
43379+
}
4337343380

4337443381
const symbol = resolveEntityName(node, meaning, /*ignoreErrors*/ true);
4337543382
return symbol && symbol !== unknownSymbol ? getTypeReferenceDirectivesForSymbol(symbol, meaning) : undefined;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [computedPropertyNameAndTypeParameterConflict.ts]
2+
declare const O: unique symbol;
3+
declare class Bar<O> {
4+
[O]: number;
5+
}
6+
7+
8+
9+
//// [computedPropertyNameAndTypeParameterConflict.js]
10+
11+
12+
//// [computedPropertyNameAndTypeParameterConflict.d.ts]
13+
declare const O: unique symbol;
14+
declare class Bar<O> {
15+
[O]: number;
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/computedPropertyNameAndTypeParameterConflict.ts ===
2+
declare const O: unique symbol;
3+
>O : Symbol(O, Decl(computedPropertyNameAndTypeParameterConflict.ts, 0, 13))
4+
5+
declare class Bar<O> {
6+
>Bar : Symbol(Bar, Decl(computedPropertyNameAndTypeParameterConflict.ts, 0, 31))
7+
>O : Symbol(O, Decl(computedPropertyNameAndTypeParameterConflict.ts, 1, 18))
8+
9+
[O]: number;
10+
>[O] : Symbol(Bar[O], Decl(computedPropertyNameAndTypeParameterConflict.ts, 1, 22))
11+
>O : Symbol(O, Decl(computedPropertyNameAndTypeParameterConflict.ts, 0, 13))
12+
}
13+
14+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/computedPropertyNameAndTypeParameterConflict.ts ===
2+
declare const O: unique symbol;
3+
>O : unique symbol
4+
5+
declare class Bar<O> {
6+
>Bar : Bar<O>
7+
8+
[O]: number;
9+
>[O] : number
10+
>O : unique symbol
11+
}
12+
13+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @declaration: true
2+
declare const O: unique symbol;
3+
declare class Bar<O> {
4+
[O]: number;
5+
}
6+

0 commit comments

Comments
 (0)