Skip to content

docs(web): UInput の属性コメントから誤った一般則を取り除く - #90

Merged
reiroop merged 1 commit into
mainfrom
fix/uinput-attr-comment
Sep 20, 2026
Merged

reiroop merged 1 commit into
mainfrom
fix/uinput-attr-comment

Conversation

@reiroop

@reiroop reiroop commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

何を直すか

apps/web/app/pages/special-invoice.vue の <UInput> の直前のコメントが、両方向に反例を持つ一般則を書いていた。

UInput accepts on the tag only the HTML attribute names that Pick lists.

このコメントを読んだ人は、Pick の列挙を見て UInput がタグで受け取る名前を判定しようとして誤る。列挙から名前を言い当てる規則そのものを書かない形に改めた。

反例

2026-09-20 に、分岐元 c81574a の作業ツリー (@nuxt/ui 4.11.1、vue-tsc 3.3.11) で、apps/web/.nuxt/tsconfig.app.json を継承し files に SFC を 1 本だけ挙げた tsconfig に対して vue-tsc --noEmit を実行した。1 ケース 1 ファイルで分離し、import UInput from '@nuxt/ui/components/Input.vue' で読み込んだ。strictTemplates と fallthroughAttributes はいずれも true である (nuxt.config.ts)。

タグに書いたもの 結果
style="color:red" / class="c" / id="x" / :enterKeyHint="'go'" / readonly / maxlength="4" / v-bind="{ inputmode: 'numeric' }" エラー 0
enterkeyhint="go" TS2561
inputmode="numeric" / bogusattr="x" (陰性対照) TS2353
  • style は Pick の列挙に無く、Input.vue.d.ts にも現れない (同じ作業ツリーで grep -c style が 0) が、タグに書ける。
  • enterkeyhint は Pick が TS の名前 enterKeyHint を持つのに、HTML の綴りでは拒否される。

エラーメッセージが名指しする型は VNodeProps & AllowedComponentProps & ComponentCustomProps & { … } で、@nuxt/ui が宣言する prop より広い。 コメントにはこの逐語を入れてある。

なぜ一般則を書かないか

列挙から受け取る名前を導く規則には、仕様にも実装にも根拠が得られなかった。 手元で確かめたケースが何件通っても一般則の根拠にはならないので、確かめた範囲だけを書いた。

この規則は 3 回書き直されて 3 回とも反例に当たっている。 v1「直接宣言されている prop だけ」、v2「Pick の列挙にある名前だけ」、v3 (c81574a でマージされたもの)「Pick が挙げている HTML 属性の名前だけ」。共通点は、ライブラリの配布物を読んで得た結論を規則として書いたことである。測定で確かめた入出力は毎回正しく、崩れたのは常に「なぜそうなるか」を配布物の中身から説明しようとした部分だった。

確かめていないこと

描画は確かめていない。 .vue の描画を確かめる手段がリポジトリに無いためで (#57)、その事実もコメントに書いた。inheritAttrs: false と、内側の <input> の v-bind="{ ...$attrs, ...ariaAttrs }" と、defineProps に inputmode / readonly / maxlength が無いことは、インストール済みの Input.vue を読んで確かめた。

コメントの言語

英語のまま残した。 このファイルのコメントは全て英語で、日本語への統一は #54 が対象として挙げている。ここで 1 箇所だけ日本語にすると、ファイルの中で言語が混ざり、#54 の作業と二重になる。git diff --name-status 293a57e...d8feaca の追加にこのファイルが含まれ、#54 のコメント行の条件に当たる行が d8feaca 時点で 7 行あることを確かめてある。

#54 の担当への申し送り: この段落を翻訳する際に、測定条件 (版番号・日付) と「一般則を書かない」という趣旨を落とさないこと。要約すると 4 回目の全称命題に戻る。

確認

pnpm lint / pnpm knip / pnpm typecheck / pnpm test / pnpm build がすべて終了コード 0。

🤖 Generated with Claude Code

special-invoice.vue の `<UInput>` 前のコメントは「`UInput` がタグで受け取るのは
@nuxt/ui の `Pick` が挙げている HTML 属性の名前だけである」と書いていたが、これは
誤りだった。両方向に反例がある。

このコメントを読んだ人は、`Pick` の列挙を見て `UInput` がタグで受け取る名前を判定
しようとして誤る。そのため、列挙から名前を言い当てる規則そのものを書かない形に
改めた。型定義の事実、すなわち @nuxt/ui が `dist/runtime/types/html.d.ts` で Vue の
型から `Pick` した自前の `InputHTMLAttributes` を宣言し、`InputProps` が
`/** @vue-ignore */ Omit<…>` でそれを継承していることは残し、そこから受け取る名前を
導く記述を削った。タグの検査対象は @nuxt/ui が宣言する prop より広く、エラー
メッセージが `VNodeProps & AllowedComponentProps & ComponentCustomProps & { … }` と
名指しする。

実測の範囲。2026-09-20 に、このコミットの分岐元 c81574a の作業ツリー(@nuxt/ui
4.11.1、vue-tsc 3.3.11)で、`apps/web/.nuxt/tsconfig.app.json` を継承し `files` に
SFC を 1 本だけ挙げた tsconfig に対して `vue-tsc --noEmit` を実行した。1 ケース
1 ファイルで分離し、`import UInput from '@nuxt/ui/components/Input.vue'` で読み込み、
Nuxt の自動 import が効かないので `ref` は vue から明示的に import した。
`strictTemplates` と `fallthroughAttributes` はいずれも true である
(nuxt.config.ts)。結果は次のとおりで、`Pick` の列挙は両方向とも結果を予測しない。

- `style="color:red"` / `class="c"` / `id="x"` / `:enterKeyHint="'go'"` /
  `readonly` / `maxlength="4"` / `v-bind="{ inputmode: 'numeric' }"` はエラー 0
- `enterkeyhint="go"` は TS2561
- `inputmode="numeric"` と、陰性対照の `bogusattr="x"` は TS2353

`style` は `Pick` の列挙に無く、`Input.vue.d.ts` にも現れない(同じ作業ツリーで
`grep -c style` が 0)が、タグに書ける。`enterkeyhint` は `Pick` が TS の名前
`enterKeyHint` を持つのに、HTML の綴りでは拒否される。

一般則を書かない理由。列挙から受け取る名前を導く規則には、仕様にも実装にも根拠が
得られなかった。手元で確かめたケースが何件通っても一般則の根拠にはならないので、
確かめた範囲だけを書いた。

描画は確かめていない。`.vue` の描画を確かめる手段がリポジトリに無いためで、その事実
もコメントに書いた(#57)。`inheritAttrs: false` と、内側の `<input>` の
`v-bind="{ ...$attrs, ...ariaAttrs }"` と、`defineProps` に `inputmode` /
`readonly` / `maxlength` が無いことは、インストール済みの `Input.vue` を読んで
確かめた。

コメントの言語は英語のまま残した。このファイルのコメントは全て英語で、日本語への
統一は #54 が対象として挙げている。ここで 1 箇所だけ日本語にすると、ファイルの中で
言語が混ざり、#54 の作業と二重になる。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 20, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 44ac31e3-0000-4305-864a-24e429977c4b


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@reiroop reiroop added the documentation Improvements or additions to documentation label Sep 20, 2026
@reiroop
reiroop merged commit 1c4345f into main Sep 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant