π 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.
π 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
π Actual behavior
JS emit with
isolatedModulesis enabled: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
preserveConstEnumsis enabled because the const enum is still inlined then. I didn't testisolatedModulesthen. I suspect the error was correct, it was just gated by the wrong flag.