Skip to content

Unflagged used before its declaration for const enum when isolatedModules is enabledΒ #57173

Closed
@frigus02

Description

@frigus02

πŸ”Ž Search Terms

isolatedModules, const enum, used before its declaration

πŸ•— Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/play?isolatedModules=true&ts=5.1.6#code/FAYw9gdgzmA2CmA6WYDmAKAYmMiCCAlANzCiRQAuABPBAK4C2V2YVA3lXgDRUBCVAX2BA

πŸ’» Code

console.log(Foo.A);
const enum Foo { A, B }

πŸ™ Actual behavior

JS emit with isolatedModules is enabled:

console.log(Foo.A);
var Foo;
(function (Foo) {
    Foo[Foo["A"] = 0] = "A";
    Foo[Foo["B"] = 1] = "B";
})(Foo || (Foo = {}));

No error.

πŸ™‚ Expected behavior

Expected "used before its declaration error" because the const enum is not inlined.

Or ... could TypeScript still inline the const enum since it's defined in the same file? I guess that might be too expensive?

Additional information about the issue

I profusely apologize. I think the behavior was changed due to #53019. I reported that the error should not happen if preserveConstEnums is enabled because the const enum is still inlined then. I didn't test isolatedModules then. I suspect the error was correct, it was just gated by the wrong flag.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions