fix-verbatim-module-syntax

1.0.0 • Public • Published

fix-verbatim-module-syntax

CLI tool to auto-fix verbatimModuleSyntax errors in your TypeScript project:

error TS1484: 'SomeType' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

Why?

verbatimModuleSyntax is a TypeScript config introduced in v5. Enabling it is highly recommended as it enforces explicit type imports/exports, ensuring predictable compilation.

Previously, TypeScript automatically detected and removed type-only imports/exports during compilation. But this could lead to runtime issues if the imported modules had side effects. To address this, verbatimModuleSyntax was introduced to require explicitly marked type imports/exports, making the code more maintainable and resilient against unexpected behavior during compilation.

However, enabling verbatimModuleSyntax may initially produce many errors related to missing type annotations. Fixing these manually can be tedious so this command-line tool automates the process for you.


Usage

Ensure TypeScript v5 is installed in your project, then run the following command in the project directory, specifying the path to your tsconfig.json.

[!WARNING] This command will modify your files. Be sure to back up or commit your changes beforehand.

npx fix-verbatim-module-syntax ./tsconfig.json

After running the command, add "verbatimModuleSyntax": true to your tsconfig.json.

Dry-run Mode

To preview changes without modifying files, use the --dry flag:

npx fix-verbatim-module-syntax --dry ./tsconfig.json

Sponsors

Package Sidebar

Install

npm i fix-verbatim-module-syntax

Weekly Downloads

5,629

Version

1.0.0

License

MIT

Unpacked Size

5.95 kB

Total Files

4

Last publish

Collaborators

  • hirokiosame