Skip to content

"used before its declaration" errors not reported when variable/enum/class is used as decorator parameter on class member #50349

@zivarah

Description

@zivarah

Bug Report

🔎 Search Terms

decorator
enum
used before its declaration
TS2448, TS2449, TS2450
isolatedModules
preserveConstEnums

🕗 Version & Regression Information

⏯ Playground Link

Workbench Repro

💻 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions