Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
frigus02 opened this issue Jan 25, 2024 · 0 comments Β· Fixed by #57174
Closed

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

frigus02 opened this issue Jan 25, 2024 · 0 comments Β· Fixed by #57174
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@frigus02
Copy link
Contributor

frigus02 commented Jan 25, 2024

πŸ”Ž 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.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jan 25, 2024
@andrewbranch andrewbranch added Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Jan 26, 2024
@andrewbranch andrewbranch added this to the TypeScript 5.4.0 milestone Jan 26, 2024
@andrewbranch andrewbranch added the Fix Available A PR has been opened for this issue label Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants