1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Lit+TypeScriptでデコレーターのエラーが出るときの対処法

Posted at

Litの公式チュートリアルにあるコードを書いていると、デコレーター部分に次のようなエラーが表示されます。これは、チュートリアルではなく自分で書いたコードでも、同様にエラーが表示されます。

image.png

式として呼び出される場合、クラス デコレーターのシグネチャを解決できません。
The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.

このエラーを解決するには、チュートリアルとは別のページに記載されている手順を実行する必要があります。一応公式ドキュメントですが、チュートリアルに書いておいて欲しいですね。

To use decorators with TypeScript, enable the experimentalDecorators compiler option.

You should also ensure that the useDefineForClassFields setting is false. Note, this should only be required when the target is set to esnext or greater, but it's recommended to explicitly ensure this setting is false.

"experimentalDecorators": true,
"useDefineForClassFields": false,

Enabling emitDecoratorMetadata is not required and not recommended.

つまり、TypeScriptの設定でexperimentalDecoratorstrueに設定し、useDefineForClassFieldsfalseに設定するということです。後者の設定は必須ではなく、targetesnext以降に設定されている場合にのみ必須ですが、明示的にfalseにすることが推奨されています。

これらの設定を変更すると、画像のように、エラーが出なくなりました。

image.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?