Vize

script/require-prop-types

要求每个 prop 声明类型。

默认严重程度 预设 自动修复 选项
error opinionated 不支持 无

适用范围:Vue SFC 中的 JS/TS 脚本;示例展示对应的 Options API 或 script setup 形式。

错误示例

数组项只声明名称 status;null 值和空描述对象也没有声明运行时 prop 类型。

<script lang="ts">
export default {
  props: ['status']            // array form: no types
}

export default {
  props: {
    status: null,              // no type
    other: {}                  // empty descriptor: no type
  }
}
</script>

正确示例

status: String 提供简写构造器,other 在描述对象内提供 type: Number,两个 props 现在都有类型声明。

<script lang="ts">
export default {
  props: {
    status: String,
    other: { type: Number, default: 0 }
  }
}
</script>

配置(Vite+)

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

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "script/require-prop-types": "error"
    }
  },
});

然后运行 vp run lint。

相关页面