Make computed property names always checked, regardless of parent grammar errors (#64674)

This commit is contained in:
Wesley Wigham authored and GitHub committed 2026-10-07 23:11:24 +00:00
1 parent a501b11f64
commit ec47d33c23
56 files changed
+873 -11

No files matched your search

+3 -6
View File
@@ -5234,6 +5234,9 @@ func (c *Checker) checkEnumMember(node *ast.Node) {
if ast.IsPrivateIdentifier(node.Name()) {
c.error(node, diagnostics.An_enum_member_cannot_be_named_with_a_private_identifier)
}
if ast.IsComputedPropertyName(node.Name()) {
c.checkExpression(node.Name().Expression())
}
if node.Initializer() != nil {
c.checkExpression(node.Initializer())
}
@@ -28792,13 +28795,7 @@ func (c *Checker) markLinkedReferences(location *ast.Node, hint ReferenceHint, p
return
}
}
// Computed property names on enum members are a grammar error and are never checked
// (checkEnumMember only checks the member initializer, not the name), so resolving
// identifiers in them here would report a spurious "Cannot find name" diagnostic.
if computedName != nil {
if ast.IsEnumMember(computedName.Parent) {
return
}
if isInvalidComputedPropertyName(computedName) {
return
}
@@ -0,0 +1,15 @@
deprecatedReferenceInEnumComputedNameNoFlake.ts(5,5): error TS1164: Computed property names are not allowed in enums.
deprecatedReferenceInEnumComputedNameNoFlake.ts(5,6): suggestion TS6385: 'oldValue' is deprecated.
==== deprecatedReferenceInEnumComputedNameNoFlake.ts (2 errors) ====
// TS6385: 'oldValue' is deprecated.
/** @deprecated */
declare const oldValue: { value: number };
export enum Values {
[oldValue.value] = 1,
~~~~~~~~~~~~~~~~
!!! error TS1164: Computed property names are not allowed in enums.
~~~~~~~~
!!! suggestion TS6385: 'oldValue' is deprecated.
}
@@ -0,0 +1,21 @@
//// [tests/cases/compiler/deprecatedReferenceInEnumComputedNameNoFlake.ts] ////
//// [deprecatedReferenceInEnumComputedNameNoFlake.ts]
// TS6385: 'oldValue' is deprecated.
/** @deprecated */
declare const oldValue: { value: number };
export enum Values {
[oldValue.value] = 1,
}
//// [deprecatedReferenceInEnumComputedNameNoFlake.js]
export var Values;
(function (Values) {
Values[Values[oldValue.value] = 1] = oldValue.value;
})(Values || (Values = {}));
//// [deprecatedReferenceInEnumComputedNameNoFlake.d.ts]
export declare enum Values {
[oldValue.value] = 1
}
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/deprecatedReferenceInEnumComputedNameNoFlake.ts] ////
=== deprecatedReferenceInEnumComputedNameNoFlake.ts ===
// TS6385: 'oldValue' is deprecated.
/** @deprecated */
declare const oldValue: { value: number };
>oldValue : Symbol(oldValue, Decl(deprecatedReferenceInEnumComputedNameNoFlake.ts, 2, 13))
>value : Symbol(value, Decl(deprecatedReferenceInEnumComputedNameNoFlake.ts, 2, 25))
export enum Values {
>Values : Symbol(Values, Decl(deprecatedReferenceInEnumComputedNameNoFlake.ts, 2, 42))
[oldValue.value] = 1,
>[oldValue.value] : Symbol(Values[oldValue.value], Decl(deprecatedReferenceInEnumComputedNameNoFlake.ts, 3, 20))
>oldValue.value : Symbol(value, Decl(deprecatedReferenceInEnumComputedNameNoFlake.ts, 2, 25))
>oldValue : Symbol(oldValue, Decl(deprecatedReferenceInEnumComputedNameNoFlake.ts, 2, 13))
>value : Symbol(value, Decl(deprecatedReferenceInEnumComputedNameNoFlake.ts, 2, 25))
}
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/deprecatedReferenceInEnumComputedNameNoFlake.ts] ////
=== deprecatedReferenceInEnumComputedNameNoFlake.ts ===
// TS6385: 'oldValue' is deprecated.
/** @deprecated */
declare const oldValue: { value: number };
>oldValue : { value: number; }
>value : number
export enum Values {
>Values : Values
[oldValue.value] = 1,
>[oldValue.value] : Values
>oldValue.value : number
>oldValue : { value: number; }
>value : number
>1 : 1
}
@@ -0,0 +1,14 @@
main.ts(4,5): error TS1164: Computed property names are not allowed in enums.
==== key.ts (0 errors) ====
export const key = "member";
==== main.ts (1 errors) ====
import { key } from "./key";
export enum Example {
[key] = 0,
~~~~~
!!! error TS1164: Computed property names are not allowed in enums.
}
@@ -0,0 +1,20 @@
//// [tests/cases/compiler/importedValueInEnumComputedNameNoFlake.ts] ////
//// [key.ts]
export const key = "member";
//// [main.ts]
import { key } from "./key";
export enum Example {
[key] = 0,
}
//// [key.js]
export const key = "member";
//// [main.js]
import { key } from "./key";
export var Example;
(function (Example) {
Example[Example[key] = 0] = key;
})(Example || (Example = {}));
@@ -0,0 +1,17 @@
//// [tests/cases/compiler/importedValueInEnumComputedNameNoFlake.ts] ////
=== key.ts ===
export const key = "member";
>key : Symbol(key, Decl(key.ts, 0, 12))
=== main.ts ===
import { key } from "./key";
>key : Symbol(key, Decl(main.ts, 0, 8))
export enum Example {
>Example : Symbol(Example, Decl(main.ts, 0, 28))
[key] = 0,
>[key] : Symbol(Example[key], Decl(main.ts, 2, 21))
>key : Symbol(key, Decl(main.ts, 0, 8))
}
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/importedValueInEnumComputedNameNoFlake.ts] ////
=== key.ts ===
export const key = "member";
>key : "member"
>"member" : "member"
=== main.ts ===
import { key } from "./key";
>key : "member"
export enum Example {
>Example : Example
[key] = 0,
>[key] : Example
>key : "member"
>0 : 0
}
@@ -0,0 +1,20 @@
incompatibleAssignmentInEnumComputedNameNoFlake.ts(4,5): error TS1164: Computed property names are not allowed in enums.
incompatibleAssignmentInEnumComputedNameNoFlake.ts(5,23): error TS2322: Type 'string' is not assignable to type 'number'.
==== incompatibleAssignmentInEnumComputedNameNoFlake.ts (2 errors) ====
// TS2322: Type 'string' is not assignable to type 'number'.
let target: number;
enum E {
[(() => {
~~~~~~~~~
const text = (target = "value");
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
return text.length;
~~~~~~~~~~~~~~~~~~~~~~~~~~~
})()]
~~~~~~~~~
!!! error TS1164: Computed property names are not allowed in enums.
}
@@ -0,0 +1,36 @@
//// [tests/cases/compiler/incompatibleAssignmentInEnumComputedNameNoFlake.ts] ////
//// [incompatibleAssignmentInEnumComputedNameNoFlake.ts]
// TS2322: Type 'string' is not assignable to type 'number'.
let target: number;
enum E {
[(() => {
const text = (target = "value");
return text.length;
})()]
}
//// [incompatibleAssignmentInEnumComputedNameNoFlake.js]
"use strict";
// TS2322: Type 'string' is not assignable to type 'number'.
let target;
var E;
(function (E) {
E[E[(() => {
const text = (target = "value");
return text.length;
})()] = 0] = (() => {
const text = (target = "value");
return text.length;
})();
})(E || (E = {}));
//// [incompatibleAssignmentInEnumComputedNameNoFlake.d.ts]
declare let target: number;
declare enum E {
[(() => {
const text = (target = "value");
return text.length;
})()] = 0
}
@@ -0,0 +1,27 @@
//// [tests/cases/compiler/incompatibleAssignmentInEnumComputedNameNoFlake.ts] ////
=== incompatibleAssignmentInEnumComputedNameNoFlake.ts ===
// TS2322: Type 'string' is not assignable to type 'number'.
let target: number;
>target : Symbol(target, Decl(incompatibleAssignmentInEnumComputedNameNoFlake.ts, 1, 3))
enum E {
>E : Symbol(E, Decl(incompatibleAssignmentInEnumComputedNameNoFlake.ts, 1, 19))
[(() => {
>[(() => { const text = (target = "value"); return text.length; })()] : Symbol(E[(() => {
const text = (target = "value");
return text.length;
})()], Decl(incompatibleAssignmentInEnumComputedNameNoFlake.ts, 2, 8))
const text = (target = "value");
>text : Symbol(text, Decl(incompatibleAssignmentInEnumComputedNameNoFlake.ts, 4, 13))
>target : Symbol(target, Decl(incompatibleAssignmentInEnumComputedNameNoFlake.ts, 1, 3))
return text.length;
>text.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
>text : Symbol(text, Decl(incompatibleAssignmentInEnumComputedNameNoFlake.ts, 4, 13))
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
})()]
}
@@ -0,0 +1,30 @@
//// [tests/cases/compiler/incompatibleAssignmentInEnumComputedNameNoFlake.ts] ////
=== incompatibleAssignmentInEnumComputedNameNoFlake.ts ===
// TS2322: Type 'string' is not assignable to type 'number'.
let target: number;
>target : number
enum E {
>E : E
[(() => {
>[(() => { const text = (target = "value"); return text.length; })()] : E
>(() => { const text = (target = "value"); return text.length; })() : number
>(() => { const text = (target = "value"); return text.length; }) : () => number
>() => { const text = (target = "value"); return text.length; } : () => number
const text = (target = "value");
>text : "value"
>(target = "value") : "value"
>target = "value" : "value"
>target : number
>"value" : "value"
return text.length;
>text.length : number
>text : "value"
>length : number
})()]
}
@@ -0,0 +1,12 @@
localReferenceInEnumComputedNameNoFlake.ts(4,5): error TS1164: Computed property names are not allowed in enums.
==== localReferenceInEnumComputedNameNoFlake.ts (1 errors) ====
// TS6133 must not report 'unused' as unread: the computed name references it.
const unused = { value: 1 };
export enum Example {
[unused.value] = 0
~~~~~~~~~~~~~~
!!! error TS1164: Computed property names are not allowed in enums.
}
@@ -0,0 +1,23 @@
//// [tests/cases/compiler/localReferenceInEnumComputedNameNoFlake.ts] ////
//// [localReferenceInEnumComputedNameNoFlake.ts]
// TS6133 must not report 'unused' as unread: the computed name references it.
const unused = { value: 1 };
export enum Example {
[unused.value] = 0
}
//// [localReferenceInEnumComputedNameNoFlake.js]
// TS6133 must not report 'unused' as unread: the computed name references it.
const unused = { value: 1 };
export var Example;
(function (Example) {
Example[Example[unused.value] = 0] = unused.value;
})(Example || (Example = {}));
//// [localReferenceInEnumComputedNameNoFlake.d.ts]
export declare enum Example {
[unused.value] = 0
}
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/localReferenceInEnumComputedNameNoFlake.ts] ////
=== localReferenceInEnumComputedNameNoFlake.ts ===
// TS6133 must not report 'unused' as unread: the computed name references it.
const unused = { value: 1 };
>unused : Symbol(unused, Decl(localReferenceInEnumComputedNameNoFlake.ts, 1, 5))
>value : Symbol(value, Decl(localReferenceInEnumComputedNameNoFlake.ts, 1, 16))
export enum Example {
>Example : Symbol(Example, Decl(localReferenceInEnumComputedNameNoFlake.ts, 1, 28))
[unused.value] = 0
>[unused.value] : Symbol(Example[unused.value], Decl(localReferenceInEnumComputedNameNoFlake.ts, 2, 21))
>unused.value : Symbol(value, Decl(localReferenceInEnumComputedNameNoFlake.ts, 1, 16))
>unused : Symbol(unused, Decl(localReferenceInEnumComputedNameNoFlake.ts, 1, 5))
>value : Symbol(value, Decl(localReferenceInEnumComputedNameNoFlake.ts, 1, 16))
}
@@ -0,0 +1,21 @@
//// [tests/cases/compiler/localReferenceInEnumComputedNameNoFlake.ts] ////
=== localReferenceInEnumComputedNameNoFlake.ts ===
// TS6133 must not report 'unused' as unread: the computed name references it.
const unused = { value: 1 };
>unused : { value: number; }
>{ value: 1 } : { value: number; }
>value : number
>1 : 1
export enum Example {
>Example : Example
[unused.value] = 0
>[unused.value] : Example
>unused.value : number
>unused : { value: number; }
>value : number
>0 : 0
}
@@ -0,0 +1,13 @@
missingIdentifierInEnumComputedNameNoFlake.ts(3,5): error TS1164: Computed property names are not allowed in enums.
missingIdentifierInEnumComputedNameNoFlake.ts(3,6): error TS2304: Cannot find name 'missing'.
==== missingIdentifierInEnumComputedNameNoFlake.ts (2 errors) ====
// TS2304: Cannot find name 'missing'.
export enum Values {
[missing.value] = 1,
~~~~~~~~~~~~~~~
!!! error TS1164: Computed property names are not allowed in enums.
~~~~~~~
!!! error TS2304: Cannot find name 'missing'.
}
@@ -0,0 +1,20 @@
//// [tests/cases/compiler/missingIdentifierInEnumComputedNameNoFlake.ts] ////
//// [missingIdentifierInEnumComputedNameNoFlake.ts]
// TS2304: Cannot find name 'missing'.
export enum Values {
[missing.value] = 1,
}
//// [missingIdentifierInEnumComputedNameNoFlake.js]
// TS2304: Cannot find name 'missing'.
export var Values;
(function (Values) {
Values[Values[missing.value] = 1] = missing.value;
})(Values || (Values = {}));
//// [missingIdentifierInEnumComputedNameNoFlake.d.ts]
export declare enum Values {
[missing.value] = 1
}
@@ -0,0 +1,10 @@
//// [tests/cases/compiler/missingIdentifierInEnumComputedNameNoFlake.ts] ////
=== missingIdentifierInEnumComputedNameNoFlake.ts ===
// TS2304: Cannot find name 'missing'.
export enum Values {
>Values : Symbol(Values, Decl(missingIdentifierInEnumComputedNameNoFlake.ts, 0, 0))
[missing.value] = 1,
>[missing.value] : Symbol(Values[missing.value], Decl(missingIdentifierInEnumComputedNameNoFlake.ts, 1, 20))
}
@@ -0,0 +1,14 @@
//// [tests/cases/compiler/missingIdentifierInEnumComputedNameNoFlake.ts] ////
=== missingIdentifierInEnumComputedNameNoFlake.ts ===
// TS2304: Cannot find name 'missing'.
export enum Values {
>Values : Values
[missing.value] = 1,
>[missing.value] : Values
>missing.value : any
>missing : any
>value : any
>1 : 1
}
@@ -0,0 +1,16 @@
missingModuleInEnumComputedNameNoFlake.ts(3,5): error TS1164: Computed property names are not allowed in enums.
missingModuleInEnumComputedNameNoFlake.ts(3,13): error TS2307: Cannot find module 'missing' or its corresponding type declarations.
missingModuleInEnumComputedNameNoFlake.ts(3,24): error TS2339: Property 'value' does not exist on type 'Promise<any>'.
==== missingModuleInEnumComputedNameNoFlake.ts (3 errors) ====
// TS2307: Cannot find module 'missing' or its corresponding type declarations.
export enum Values {
[import("missing").value] = 1,
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1164: Computed property names are not allowed in enums.
~~~~~~~~~
!!! error TS2307: Cannot find module 'missing' or its corresponding type declarations.
~~~~~
!!! error TS2339: Property 'value' does not exist on type 'Promise<any>'.
}
@@ -0,0 +1,20 @@
//// [tests/cases/compiler/missingModuleInEnumComputedNameNoFlake.ts] ////
//// [missingModuleInEnumComputedNameNoFlake.ts]
// TS2307: Cannot find module 'missing' or its corresponding type declarations.
export enum Values {
[import("missing").value] = 1,
}
//// [missingModuleInEnumComputedNameNoFlake.js]
// TS2307: Cannot find module 'missing' or its corresponding type declarations.
export var Values;
(function (Values) {
Values[Values[import("missing").value] = 1] = import("missing").value;
})(Values || (Values = {}));
//// [missingModuleInEnumComputedNameNoFlake.d.ts]
export declare enum Values {
[import("missing").value] = 1
}
@@ -0,0 +1,10 @@
//// [tests/cases/compiler/missingModuleInEnumComputedNameNoFlake.ts] ////
=== missingModuleInEnumComputedNameNoFlake.ts ===
// TS2307: Cannot find module 'missing' or its corresponding type declarations.
export enum Values {
>Values : Symbol(Values, Decl(missingModuleInEnumComputedNameNoFlake.ts, 0, 0))
[import("missing").value] = 1,
>[import("missing").value] : Symbol(Values[import("missing").value], Decl(missingModuleInEnumComputedNameNoFlake.ts, 1, 20))
}
@@ -0,0 +1,15 @@
//// [tests/cases/compiler/missingModuleInEnumComputedNameNoFlake.ts] ////
=== missingModuleInEnumComputedNameNoFlake.ts ===
// TS2307: Cannot find module 'missing' or its corresponding type declarations.
export enum Values {
>Values : Values
[import("missing").value] = 1,
>[import("missing").value] : Values
>import("missing").value : any
>import("missing") : Promise<any>
>"missing" : "missing"
>value : any
>1 : 1
}
@@ -0,0 +1,15 @@
misspelledIdentifierInEnumComputedNameNoFlake.ts(4,5): error TS1164: Computed property names are not allowed in enums.
misspelledIdentifierInEnumComputedNameNoFlake.ts(4,6): error TS2552: Cannot find name 'existingVale'. Did you mean 'existingValue'?
==== misspelledIdentifierInEnumComputedNameNoFlake.ts (2 errors) ====
// TS2552: Cannot find name 'existingVale'. Did you mean 'existingValue'?
declare const existingValue: { value: number };
export enum Values {
[existingVale.value] = 1,
~~~~~~~~~~~~~~~~~~~~
!!! error TS1164: Computed property names are not allowed in enums.
~~~~~~~~~~~~
!!! error TS2552: Cannot find name 'existingVale'. Did you mean 'existingValue'?
!!! related TS2728 misspelledIdentifierInEnumComputedNameNoFlake.ts:2:15: 'existingValue' is declared here.
}
@@ -0,0 +1,20 @@
//// [tests/cases/compiler/misspelledIdentifierInEnumComputedNameNoFlake.ts] ////
//// [misspelledIdentifierInEnumComputedNameNoFlake.ts]
// TS2552: Cannot find name 'existingVale'. Did you mean 'existingValue'?
declare const existingValue: { value: number };
export enum Values {
[existingVale.value] = 1,
}
//// [misspelledIdentifierInEnumComputedNameNoFlake.js]
export var Values;
(function (Values) {
Values[Values[existingVale.value] = 1] = existingVale.value;
})(Values || (Values = {}));
//// [misspelledIdentifierInEnumComputedNameNoFlake.d.ts]
export declare enum Values {
[existingVale.value] = 1
}
@@ -0,0 +1,14 @@
//// [tests/cases/compiler/misspelledIdentifierInEnumComputedNameNoFlake.ts] ////
=== misspelledIdentifierInEnumComputedNameNoFlake.ts ===
// TS2552: Cannot find name 'existingVale'. Did you mean 'existingValue'?
declare const existingValue: { value: number };
>existingValue : Symbol(existingValue, Decl(misspelledIdentifierInEnumComputedNameNoFlake.ts, 1, 13))
>value : Symbol(value, Decl(misspelledIdentifierInEnumComputedNameNoFlake.ts, 1, 30))
export enum Values {
>Values : Symbol(Values, Decl(misspelledIdentifierInEnumComputedNameNoFlake.ts, 1, 47))
[existingVale.value] = 1,
>[existingVale.value] : Symbol(Values[existingVale.value], Decl(misspelledIdentifierInEnumComputedNameNoFlake.ts, 2, 20))
}
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/misspelledIdentifierInEnumComputedNameNoFlake.ts] ////
=== misspelledIdentifierInEnumComputedNameNoFlake.ts ===
// TS2552: Cannot find name 'existingVale'. Did you mean 'existingValue'?
declare const existingValue: { value: number };
>existingValue : { value: number; }
>value : number
export enum Values {
>Values : Values
[existingVale.value] = 1,
>[existingVale.value] : Values
>existingVale.value : any
>existingVale : any
>value : any
>1 : 1
}
@@ -0,0 +1,24 @@
redundantDeclareInEnumComputedNameNoFlake.ts(3,5): error TS1164: Computed property names are not allowed in enums.
redundantDeclareInEnumComputedNameNoFlake.ts(4,9): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module.
redundantDeclareInEnumComputedNameNoFlake.ts(5,13): error TS1038: A 'declare' modifier cannot be used in an already ambient context.
==== redundantDeclareInEnumComputedNameNoFlake.ts (3 errors) ====
// TS1038: A 'declare' modifier cannot be used in an already ambient context.
export enum Values {
[(function () {
~~~~~~~~~~~~~~~
declare namespace Nested {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~
!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module.
declare const value: number;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~
!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context.
}
~~~~~~~~~
}).name] = 1,
~~~~~~~~~~~~
!!! error TS1164: Computed property names are not allowed in enums.
}
@@ -0,0 +1,30 @@
//// [tests/cases/compiler/redundantDeclareInEnumComputedNameNoFlake.ts] ////
//// [redundantDeclareInEnumComputedNameNoFlake.ts]
// TS1038: A 'declare' modifier cannot be used in an already ambient context.
export enum Values {
[(function () {
declare namespace Nested {
declare const value: number;
}
}).name] = 1,
}
//// [redundantDeclareInEnumComputedNameNoFlake.js]
// TS1038: A 'declare' modifier cannot be used in an already ambient context.
export var Values;
(function (Values) {
Values[Values[(function () {
}).name] = 1] = (function () {
}).name;
})(Values || (Values = {}));
//// [redundantDeclareInEnumComputedNameNoFlake.d.ts]
export declare enum Values {
[(function () {
declare namespace Nested {
declare const value: number;
}
}).name] = 1
}
@@ -0,0 +1,24 @@
//// [tests/cases/compiler/redundantDeclareInEnumComputedNameNoFlake.ts] ////
=== redundantDeclareInEnumComputedNameNoFlake.ts ===
// TS1038: A 'declare' modifier cannot be used in an already ambient context.
export enum Values {
>Values : Symbol(Values, Decl(redundantDeclareInEnumComputedNameNoFlake.ts, 0, 0))
[(function () {
>[(function () { declare namespace Nested { declare const value: number; } }).name] : Symbol(Values[(function () {
declare namespace Nested {
declare const value: number;
}
}).name], Decl(redundantDeclareInEnumComputedNameNoFlake.ts, 1, 20))
>(function () { declare namespace Nested { declare const value: number; } }).name : Symbol(Function.name, Decl(lib.es2015.core.d.ts, --, --))
declare namespace Nested {
>Nested : Symbol(Nested, Decl(redundantDeclareInEnumComputedNameNoFlake.ts, 2, 19))
declare const value: number;
>value : Symbol(value, Decl(redundantDeclareInEnumComputedNameNoFlake.ts, 4, 25))
}
}).name] = 1,
>name : Symbol(Function.name, Decl(lib.es2015.core.d.ts, --, --))
}
@@ -0,0 +1,23 @@
//// [tests/cases/compiler/redundantDeclareInEnumComputedNameNoFlake.ts] ////
=== redundantDeclareInEnumComputedNameNoFlake.ts ===
// TS1038: A 'declare' modifier cannot be used in an already ambient context.
export enum Values {
>Values : Values
[(function () {
>[(function () { declare namespace Nested { declare const value: number; } }).name] : Values
>(function () { declare namespace Nested { declare const value: number; } }).name : string
>(function () { declare namespace Nested { declare const value: number; } }) : () => void
>function () { declare namespace Nested { declare const value: number; } } : () => void
declare namespace Nested {
>Nested : typeof Nested
declare const value: number;
>value : number
}
}).name] = 1,
>name : string
>1 : 1
}
@@ -0,0 +1,15 @@
stringIncrementInEnumComputedNameNoFlake.ts(4,5): error TS1164: Computed property names are not allowed in enums.
stringIncrementInEnumComputedNameNoFlake.ts(4,7): error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.
==== stringIncrementInEnumComputedNameNoFlake.ts (2 errors) ====
// TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.
declare let text: string;
export enum Values {
[(text++).valueOf] = 1,
~~~~~~~~~~~~~~~~~~
!!! error TS1164: Computed property names are not allowed in enums.
~~~~
!!! error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.
}
@@ -0,0 +1,21 @@
//// [tests/cases/compiler/stringIncrementInEnumComputedNameNoFlake.ts] ////
//// [stringIncrementInEnumComputedNameNoFlake.ts]
// TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.
declare let text: string;
export enum Values {
[(text++).valueOf] = 1,
}
//// [stringIncrementInEnumComputedNameNoFlake.js]
export var Values;
(function (Values) {
Values[Values[(text++).valueOf] = 1] = (text++).valueOf;
})(Values || (Values = {}));
//// [stringIncrementInEnumComputedNameNoFlake.d.ts]
export declare enum Values {
[(text++).valueOf] = 1
}
@@ -0,0 +1,17 @@
//// [tests/cases/compiler/stringIncrementInEnumComputedNameNoFlake.ts] ////
=== stringIncrementInEnumComputedNameNoFlake.ts ===
// TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.
declare let text: string;
>text : Symbol(text, Decl(stringIncrementInEnumComputedNameNoFlake.ts, 1, 11))
export enum Values {
>Values : Symbol(Values, Decl(stringIncrementInEnumComputedNameNoFlake.ts, 1, 25))
[(text++).valueOf] = 1,
>[(text++).valueOf] : Symbol(Values[(text++).valueOf], Decl(stringIncrementInEnumComputedNameNoFlake.ts, 2, 20))
>(text++).valueOf : Symbol(Number.valueOf, Decl(lib.es5.d.ts, --, --))
>text : Symbol(text, Decl(stringIncrementInEnumComputedNameNoFlake.ts, 1, 11))
>valueOf : Symbol(Number.valueOf, Decl(lib.es5.d.ts, --, --))
}
@@ -0,0 +1,20 @@
//// [tests/cases/compiler/stringIncrementInEnumComputedNameNoFlake.ts] ////
=== stringIncrementInEnumComputedNameNoFlake.ts ===
// TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.
declare let text: string;
>text : string
export enum Values {
>Values : Values
[(text++).valueOf] = 1,
>[(text++).valueOf] : Values
>(text++).valueOf : () => number
>(text++) : number
>text++ : number
>text : string
>valueOf : () => number
>1 : 1
}
@@ -0,0 +1,14 @@
unusedCommaOperandInEnumComputedNameNoFlake.ts(3,5): error TS1164: Computed property names are not allowed in enums.
unusedCommaOperandInEnumComputedNameNoFlake.ts(3,7): error TS2695: Left side of comma operator is unused and has no side effects.
==== unusedCommaOperandInEnumComputedNameNoFlake.ts (2 errors) ====
// TS2695: Left side of comma operator is unused and has no side effects.
export enum Values {
[(1, 2).valueOf] = 1,
~~~~~~~~~~~~~~~~
!!! error TS1164: Computed property names are not allowed in enums.
~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
}
@@ -0,0 +1,21 @@
//// [tests/cases/compiler/unusedCommaOperandInEnumComputedNameNoFlake.ts] ////
//// [unusedCommaOperandInEnumComputedNameNoFlake.ts]
// TS2695: Left side of comma operator is unused and has no side effects.
export enum Values {
[(1, 2).valueOf] = 1,
}
//// [unusedCommaOperandInEnumComputedNameNoFlake.js]
// TS2695: Left side of comma operator is unused and has no side effects.
export var Values;
(function (Values) {
Values[Values[(1, 2).valueOf] = 1] = (1, 2).valueOf;
})(Values || (Values = {}));
//// [unusedCommaOperandInEnumComputedNameNoFlake.d.ts]
export declare enum Values {
[(1, 2).valueOf] = 1
}
@@ -0,0 +1,13 @@
//// [tests/cases/compiler/unusedCommaOperandInEnumComputedNameNoFlake.ts] ////
=== unusedCommaOperandInEnumComputedNameNoFlake.ts ===
// TS2695: Left side of comma operator is unused and has no side effects.
export enum Values {
>Values : Symbol(Values, Decl(unusedCommaOperandInEnumComputedNameNoFlake.ts, 0, 0))
[(1, 2).valueOf] = 1,
>[(1, 2).valueOf] : Symbol(Values[(1, 2).valueOf], Decl(unusedCommaOperandInEnumComputedNameNoFlake.ts, 1, 20))
>(1, 2).valueOf : Symbol(Number.valueOf, Decl(lib.es5.d.ts, --, --))
>valueOf : Symbol(Number.valueOf, Decl(lib.es5.d.ts, --, --))
}
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/unusedCommaOperandInEnumComputedNameNoFlake.ts] ////
=== unusedCommaOperandInEnumComputedNameNoFlake.ts ===
// TS2695: Left side of comma operator is unused and has no side effects.
export enum Values {
>Values : Values
[(1, 2).valueOf] = 1,
>[(1, 2).valueOf] : Values
>(1, 2).valueOf : () => number
>(1, 2) : 2
>1, 2 : 2
>1 : 1
>2 : 2
>valueOf : () => number
>1 : 1
}
@@ -1,9 +1,13 @@
parserComputedPropertyName16.ts(2,3): error TS1164: Computed property names are not allowed in enums.
parserComputedPropertyName16.ts(2,4): error TS2552: Cannot find name 'e'. Did you mean 'E'?
==== parserComputedPropertyName16.ts (1 errors) ====
==== parserComputedPropertyName16.ts (2 errors) ====
enum E {
[e] = 1
~~~
!!! error TS1164: Computed property names are not allowed in enums.
~
!!! error TS2552: Cannot find name 'e'. Did you mean 'E'?
!!! related TS2728 parserComputedPropertyName16.ts:1:6: 'E' is declared here.
}
@@ -1,13 +1,17 @@
parserComputedPropertyName26.ts(3,5): error TS1164: Computed property names are not allowed in enums.
parserComputedPropertyName26.ts(3,6): error TS2552: Cannot find name 'e'. Did you mean 'E'?
parserComputedPropertyName26.ts(4,6): error TS2304: Cannot find name 'e2'.
==== parserComputedPropertyName26.ts (2 errors) ====
==== parserComputedPropertyName26.ts (3 errors) ====
enum E {
// No ASI
[e] = 0
~~~
!!! error TS1164: Computed property names are not allowed in enums.
~
!!! error TS2552: Cannot find name 'e'. Did you mean 'E'?
!!! related TS2728 parserComputedPropertyName26.ts:1:6: 'E' is declared here.
[e2] = 1
~~
!!! error TS2304: Cannot find name 'e2'.
@@ -1,15 +1,20 @@
parserComputedPropertyName30.ts(3,5): error TS1164: Computed property names are not allowed in enums.
parserComputedPropertyName30.ts(3,6): error TS2552: Cannot find name 'e'. Did you mean 'E'?
parserComputedPropertyName30.ts(3,11): error TS2304: Cannot find name 'id'.
parserComputedPropertyName30.ts(4,5): error TS1357: An enum member name must be followed by a ',', '=', or '}'.
parserComputedPropertyName30.ts(4,5): error TS1164: Computed property names are not allowed in enums.
parserComputedPropertyName30.ts(4,6): error TS2304: Cannot find name 'e2'.
==== parserComputedPropertyName30.ts (4 errors) ====
==== parserComputedPropertyName30.ts (6 errors) ====
enum E {
// no ASI, comma expected
[e] = id++
~~~
!!! error TS1164: Computed property names are not allowed in enums.
~
!!! error TS2552: Cannot find name 'e'. Did you mean 'E'?
!!! related TS2728 parserComputedPropertyName30.ts:1:6: 'E' is declared here.
~~
!!! error TS2304: Cannot find name 'id'.
[e2] = 1
@@ -17,4 +22,6 @@ parserComputedPropertyName30.ts(4,5): error TS1164: Computed property names are
!!! error TS1357: An enum member name must be followed by a ',', '=', or '}'.
~~~~
!!! error TS1164: Computed property names are not allowed in enums.
~~
!!! error TS2304: Cannot find name 'e2'.
}
@@ -1,17 +1,24 @@
parserComputedPropertyName34.ts(3,5): error TS1164: Computed property names are not allowed in enums.
parserComputedPropertyName34.ts(3,6): error TS2552: Cannot find name 'e'. Did you mean 'E'?
parserComputedPropertyName34.ts(3,11): error TS2304: Cannot find name 'id'.
parserComputedPropertyName34.ts(4,5): error TS1164: Computed property names are not allowed in enums.
parserComputedPropertyName34.ts(4,6): error TS2304: Cannot find name 'e2'.
==== parserComputedPropertyName34.ts (3 errors) ====
==== parserComputedPropertyName34.ts (5 errors) ====
enum E {
// no ASI, comma expected
[e] = id++,
~~~
!!! error TS1164: Computed property names are not allowed in enums.
~
!!! error TS2552: Cannot find name 'e'. Did you mean 'E'?
!!! related TS2728 parserComputedPropertyName34.ts:1:6: 'E' is declared here.
~~
!!! error TS2304: Cannot find name 'id'.
[e2] = 1
~~~~
!!! error TS1164: Computed property names are not allowed in enums.
~~
!!! error TS2304: Cannot find name 'e2'.
}
@@ -1,9 +1,13 @@
parserES5ComputedPropertyName6.ts(2,3): error TS1164: Computed property names are not allowed in enums.
parserES5ComputedPropertyName6.ts(2,4): error TS2552: Cannot find name 'e'. Did you mean 'E'?
==== parserES5ComputedPropertyName6.ts (1 errors) ====
==== parserES5ComputedPropertyName6.ts (2 errors) ====
enum E {
[e] = 1
~~~
!!! error TS1164: Computed property names are not allowed in enums.
~
!!! error TS2552: Cannot find name 'e'. Did you mean 'E'?
!!! related TS2728 parserES5ComputedPropertyName6.ts:1:6: 'E' is declared here.
}
@@ -0,0 +1,9 @@
// @declaration: true
// @captureSuggestions: true
// TS6385: 'oldValue' is deprecated.
/** @deprecated */
declare const oldValue: { value: number };
export enum Values {
[oldValue.value] = 1,
}
@@ -0,0 +1,12 @@
// @target: esnext
// @module: esnext
// @filename: key.ts
export const key = "member";
// @filename: main.ts
import { key } from "./key";
export enum Example {
[key] = 0,
}
@@ -0,0 +1,10 @@
// @declaration: true
// TS2322: Type 'string' is not assignable to type 'number'.
let target: number;
enum E {
[(() => {
const text = (target = "value");
return text.length;
})()]
}
@@ -0,0 +1,8 @@
// @declaration: true
// @noUnusedLocals: true
// TS6133 must not report 'unused' as unread: the computed name references it.
const unused = { value: 1 };
export enum Example {
[unused.value] = 0
}
@@ -0,0 +1,6 @@
// @declaration: true
// TS2304: Cannot find name 'missing'.
export enum Values {
[missing.value] = 1,
}
@@ -0,0 +1,8 @@
// @target: esnext
// @module: esnext
// @declaration: true
// TS2307: Cannot find module 'missing' or its corresponding type declarations.
export enum Values {
[import("missing").value] = 1,
}
@@ -0,0 +1,7 @@
// @declaration: true
// TS2552: Cannot find name 'existingVale'. Did you mean 'existingValue'?
declare const existingValue: { value: number };
export enum Values {
[existingVale.value] = 1,
}
@@ -0,0 +1,11 @@
// @target: esnext
// @declaration: true
// TS1038: A 'declare' modifier cannot be used in an already ambient context.
export enum Values {
[(function () {
declare namespace Nested {
declare const value: number;
}
}).name] = 1,
}
@@ -0,0 +1,7 @@
// @declaration: true
// TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.
declare let text: string;
export enum Values {
[(text++).valueOf] = 1,
}
@@ -0,0 +1,6 @@
// @declaration: true
// TS2695: Left side of comma operator is unused and has no side effects.
export enum Values {
[(1, 2).valueOf] = 1,
}