-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Milestone
Description
Bug Report
🔎 Search Terms
decorator
enum
used before its declaration
TS2448, TS2449, TS2450
isolatedModules
preserveConstEnums
🕗 Version & Regression Information
- This is a crash: In the transpiled JavaScript, not in tsc itself.
- This is the behavior in every version I tried (3.1 through 4.7), and I reviewed the FAQ for entries about decorators (https://github.com/Microsoft/TypeScript/wiki/FAQ#decorators)
⏯ Playground Link
💻 Code
// @experimentalDecorators: true
function methodDecorator(value: string): any {
return () => {};
}
//@methodDecorator(MyEnum.value1) // Correctly reports Enum 'MyEnum' used before its declaration (TS2450)
export class MyClass {
@methodDecorator(MyEnum.value1) // No error reported
public foo(): void {
}
}
enum MyEnum {
value1 = "value1",
}🙁 Actual behavior
- No TS2450 "Enum 'MyEnum' used before its declaration" is reported.
- At runtime, this code crashes during the initial script execution:
C:\repos\TS2450_decorator_repro\program.js:19
methodDecorator(MyEnum.value1) // No error reported
^
TypeError: Cannot read properties of undefined (reading 'value1')
at C:\repos\TS2450_decorator_repro\program.js:19:32
at Object.<anonymous> (C:\repos\TS2450_decorator_repro\program.js:22:2)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
🙂 Expected behavior
TS2450 (and other similar errors like 2448 for Block-scoped variables or 2449 for classes) should be correctly reported.
zatlodan