TypeScript: When an enum is imported and used only as a type with "verbatimModuleSyntax" enabled, an error is not being shown

🔎 Search Terms

“verbatimModuleSyntax”, “enum”

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about “verbatimModuleSyntax” (there wasn’t any) and “enums”.

⏯ Playground Link

https://www.typescriptlang.org/dev/bug-workbench/?verbatimModuleSyntax=true&ts=5.0.4#code/PTAEAEDcFMCcCMCGAXAlgWwLIHsAmBXAG2gGUBPAO2UQA8AuUZWfaAKFZAgDNViLF00Bj2IBaAO6pkAC1HQaAB2yxkAOmQBnVvKUrQ0CvnSgA6stwbQAb1ag7oAIKgAvKABEDtwBpb9gEIu7n7erAC+7DrKyIxkCtCm5oEaTKgUAOYA3Oyc4CIGAkKgqbjy6loYutFWCbAWXjW4oKGgXLDYxm6qwHkSUrKRKm7sxNGIDGa1WSOgiBRkE7jj5hoZQA

💻 Code

// @verbatimModuleSyntax: true

// @filename: file-with-export.ts
export enum Words {
    A = "A",
    B = "B",
}

export type Word = string;

// @filename: index.ts
import { Words, Word } from "./file-with-export"

let a: Word;
let anyWord: Words;

🙁 Actual behavior

The import of the Words enum doesn’t show any errors.

🙂 Expected behavior

The import of the Words enum should show a 1484 error.

Additional information about the issue

The mentioned import should show an error because it’s being used only as a type and the “verbatimModuleSyntax” flag is enabled.

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 18 (10 by maintainers)

Most upvoted comments

@jakebailey I hope you still have a colon.

Some combo of those rules, sure. You do probably want the rule I mentioned if you want to be warned that import { type A } from "..." will turn into import {} from "..." at runtime.

I had a colon

My cropping is better

If the output JS had this import removed, that’d be a bug, but the flag doesn’t tell you that you could switch an import to a type import because it’s only used in type positions. verbatimModuleSyntax means “only type annotated imports are removed” and that’s it.

If you want to be told to use a type import when possible, you need: https://typescript-eslint.io/rules/no-import-type-side-effects/

It’s in the documentation of the rule, here. Actually, it’s already deprecated. 😅