Vize

type/require-typed-props

defineProps に型定義を指定します。

既定の重大度 プリセット 自動修正 オプション
warning happy-path, nuxt, ecosystem, opinionated なし なし

適用範囲:Vue SFC の script とテンプレートの型情報。例に示した構文が対象です。

このルールは TypeScript プロジェクト(tsconfig.json)の型情報を使うため、設定で typeAware: true を指定しています。typeAware だけでは、個別に有効化するルールは有効になりません。

悪い例

配列だけの defineProps(["title"]) は title の名前だけを宣言し、型を指定していません。

<script setup lang="ts">
defineProps(["title"]);
</script>

良い例

defineProps<{ title: string }>() で、名前だけの実行時宣言に代えて title の string 型を明示します。

<script setup lang="ts">
defineProps<{ title: string }>();
</script>

設定(Vite+)

import { defineConfig } from "@vizejs/vite-plugin/vite-plus";

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "type/require-typed-props": "warn"
    },
    "typeAware": true
  },
});

設定したら vp run lint を実行します。

関連ページ