Skip to content
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

verbatimModuleSyntax and exported const enum #52669

Closed
magic-akari opened this issue Feb 8, 2023 · 11 comments · Fixed by #52746
Closed

verbatimModuleSyntax and exported const enum #52669

magic-akari opened this issue Feb 8, 2023 · 11 comments · Fixed by #52746
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@magic-akari
Copy link
Contributor

Bug Report

verbatimModuleSyntax will be introduced in [email protected] and importsNotUsedAsValues and preserveValueImports will be deprecated.
But there is a const enum export issue that has not been fixed.

🔎 Search Terms

  • verbatimModuleSyntax
  • export const enum
  • importsNotUsedAsValues
  • preserveValueImports

🕗 Version & Regression Information

[email protected]

⏯ Playground Link

Playground link with relevant code

Playground multi-file mode is broken.
Check this gist

💻 Code

// @filename: foo.ts
export const enum Foo {
  x = 1,
}

// @filename: main.ts
import { Foo } from "./foo.js";
// You cannot write something like the following
// import type { Foo } from "./foo.js";

console.log(Foo.x);

🙁 Actual behavior

SyntaxError: The requested module './foo.js' does not provide an export named 'Foo'

🙂 Expected behavior

TSC Report Error: const enum cannot be exported in verbatimModuleSyntax mode.

🔗 related issue

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Feb 8, 2023

I believe this is by-design unless you run with preserveConstEnums. CC @andrewbranch

@andrewbranch
Copy link
Member

verbatimModuleSyntax is supposed to be a superset of isolatedModules which is supposed to imply preserveConstEnums, IIRC.

@andrewbranch andrewbranch added the Needs Investigation This issue needs a team member to investigate its status. label Feb 8, 2023
@andrewbranch andrewbranch self-assigned this Feb 8, 2023
@andrewbranch andrewbranch added this to the TypeScript 5.0.1 milestone Feb 8, 2023
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Feb 8, 2023

I think it just errors when preserveConstEnums isn't enabled - I don't think it actually enables it. But I could be wrong!

@andrewbranch
Copy link
Member

isolatedModules does imply preserveConstEnum, but there were many places in the codebase where I forgot to replace an options.isolatedModules with a check for isolatedModules or verbatimModuleSyntax.

@mrazauskas
Copy link

mrazauskas commented Aug 19, 2023

Would it be possible to mentioned in the documentation that verbatimModuleSyntax: true does influence const enums?

I noticed that const enums are not inlined at use sites with verbatimModuleSyntax: true. Looks like the behaviour is similar to isolatedModules: true, but it can be I missed something.

EDIT Perhaps isolatedModules should be replaced with verbatimModuleSyntax in all places there documentation speaks about const enums? Simply because isolatedModules got deprecated and replaced with verbatimModuleSyntax? Or that is not exactly correct?

@andrewbranch
Copy link
Member

isolatedModules isn’t deprecated 🤔

@mrazauskas
Copy link

Ups.. I got mixed up. Despite of that, it would be useful to mention in documentation how verbatimModuleSyntax works with const enum.

@andrewbranch
Copy link
Member

I’m not totally convinced that isolatedModules should actually mess with const enum inlining. It’s supposed to be simply a set of checks that code can be transpiled with only single-file info, but somewhere along the way I think someone got mixed up and decided it should emit as if it lacks whole-program info. But that principle isn’t consistently applied, and I don’t see why it would be desirable anyway.

@mrazauskas
Copy link

mrazauskas commented Aug 21, 2023

Are you trying to say that this is possibly a bug? I mean, it felt like const enums should be inlined with verbatimModuleSyntax: true, but it can be I missed some detail.

Would it make sense to open a separate issue? I can do. Just didn’t want to create unnecessary noise.

@andrewbranch
Copy link
Member

I’m catching up here: #16671

@curiousdannii
Copy link

I had to add verbatimModuleSyntax to use Svelte, and now my const enums aren't optimised. This is quite unfortunate, and also seemingly undocumented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
6 participants