Closed
Description
π Search Terms
isolatedModules, const enum, used before its declaration
π Version & Regression Information
- This changed between versions v5.0.4 and v5.1.6
- I think this changed in Removed unnecessary use-before-define error for const enumsΒ #53625
β― Playground Link
π» 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.