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
💻 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)
@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 intoimport {} 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. 😅