Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scaffold): typed-query-selectorの追加 #53

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

arktds
Copy link

@arktds arktds commented Jun 14, 2024

scaffold に typed-query-selector を追加しました。

querySelector() または querySelectorAll() に不正な文字列を指定した場合、never 型になる strict モードのインポートを推奨しています。
https://github.com/g-plane/typed-query-selector?tab=readme-ov-file#strict-mode

close #50

@arktds arktds self-assigned this Jun 14, 2024
@arktds arktds requested a review from YusukeHirao as a code owner June 14, 2024 02:47
Comment on lines 1 to 3
// querySelector() または querySelectorAll() を実行する場合、次の import 文を有効にしてください。
// import 'typed-query-selector/strict.js';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arktds

デフォルト有効でいいと思います。
ガイドラインにIssueを立てて、利用するように促しましょう。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

querySelector() または querySelectorAll() を実行しない場合、無駄なインポートになる(ビルド後にコードはバンドルされませんが)かなと思いコメントアウトしました。
とはいえ、たしかにほとんどの場合実行すると思うので、有効にします!

ガイドラインでも促します!

@arktds
Copy link
Author

arktds commented Jun 14, 2024

テスト落ちてしまいました。

[vite]: Rollup failed to resolve import "typed-query-selector/strict.js" from "/Users/runner/work/frontend-env/frontend-env/packages/@d-zero/scaffold/__assets/_libs/script/index.ts".

現状の拡張子付きインポートにパス補完もされて、型推論が実際に有効になっていることを確認していたのですが、Vite(Rollup)的には駄目なのでしょうか。

import 'typed-query-selector/strict.js';

一方、たしかに typed-query-selector のドキュメントでは拡張子なしインポートになっていますが、これだと型推論が効かず Element のままになってしまいます。

import 'typed-query-selector/strict';

ESM、TS のインポート周りに詳しくない(奥が深すぎる)ので、調べます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

typed-query-selectorを導入する
2 participants