script/require-prop-type-constructor
Exigir que os valores de type de props sejam construtores em vez de literais de string.
| Severidade padrão | Predefinições | Correção automática | Opções |
|---|---|---|---|
error |
essential, happy-path, ecosystem, nuxt, opinionated |
Não | Nenhuma |
Aplicável a: Scripts JS/TS em SFCs Vue; os exemplos mostram a forma relevante de Options API ou script setup.
Incorreto
As declarações de props usam as strings "String" e "Number" como tipos de tempo de execução, inclusive dentro do array de construtores. Essas strings não são funções construtoras.
<script lang="ts">
export default {
props: {
// The type should be the `String` constructor, not the string "String".
name: "String",
age: { type: "Number" },
id: { type: ["String", "Number"] }
}
}
</script>
Correto
As declarações usam os identificadores reais String e Number, inclusive no array de união [String, Number].
<script lang="ts">
export default {
props: {
name: String,
age: { type: Number },
id: { type: [String, Number] }
}
}
</script>
Configuração (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"script/require-prop-type-constructor": "error"
}
},
});
Depois, execute vp run lint.