JavaScriptTypeScript

「Option ‘importsNotUsedAsValues’ is deprecated and will stop functioning in TypeScript 5.5.」エラーに遭遇した時の覚書

TypeDocを使用する際に発生したエラーに関する解決方法を見つけました。TypeScript 5.5以前で作成されたものを新しいバージョンで実行する場合に発生するエラーについて説明があり、解決策はtsconfig.jsonファイルで”verbatimModuleSyntax”をtrueに変更することです。これにより、エラーが解決されます。関連リンクも参考になります。

広告ここから
広告ここまで

TypeDocを実行しようとした際、タイトルのエラーに遭遇することがありました。

$ npx typedoc ./src/index.ts --out ./docs/api-reference --tsconfig ./tsconfig.json
Need to install the following packages:
  typedoc@0.25.13
Ok to proceed? (y) y
error TS5101: Option 'importsNotUsedAsValues' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '"ignoreDeprecations": "5.0"' to silence this error.
  Use 'verbatimModuleSyntax' instead.

TypeScriptのリポジトリにエラー内容がと関連する変更があったのでTypeScript 5.5以前で作られたものを、新しいバージョンで動かすときにエラーがでる・・・っぽいです。

importsNotUsedAsValues was made to serve the opposite purpose you (and basically everyone) were using it for. By default, TypeScript elides unneeded import statements from JS emit even without marking them as type imports. importsNotUsedAsValues was created as a way to escape that behavior, not (primarily) to make it more explicit. verbatimModuleSyntax allows you to escape the elision behavior, and takes the explicitness of what your imports mean a step further by making you write CJS-style imports when emitting to CJS. So in my book, all the important cases that importsNotUsedAsValues (and preserveValueImports) covered, plus more, are covered by verbatimModuleSyntax, which is way more explainable. It’s mostly a matter of reducing complexity for the sake of explanation.
https://github.com/microsoft/TypeScript/pull/52203#issuecomment-1476574601

解決策もドキュメントに記載されていますので、tsconfig.jsonを変更しましょう。

{
  "compilerOptions": {
-   "importsNotUsedAsValues": "error",
+   "verbatimModuleSyntax": true,
...

これでエラーが解決できました。

関連リンク

ブックマークや限定記事(予定)など

WP Kyotoサポーター募集中

WordPressやフロントエンドアプリのホスティング、Algolia・AWSなどのサービス利用料を支援する「WP Kyotoサポーター」を募集しています。
月額または年額の有料プランを契約すると、ブックマーク機能などのサポーター限定機能がご利用いただけます。

14日間のトライアルも用意しておりますので、「このサイトよく見るな」という方はぜひご検討ください。

広告ここから
広告ここまで

Related Category posts