type/no-redundant-type-constituents
Proibir membros de uniões e interseções que não acrescentam ou substituem informação de tipo.
| Severidade padrão | Predefinições | Correção automática | Opções |
|---|---|---|---|
warning |
nuxt, opinionated |
Não | Nenhuma |
Aplicável a: Informações de tipos em scripts e templates de SFCs Vue, para as construções mostradas abaixo.
Esta regra lê informações de tipo do seu projeto TypeScript (tsconfig.json), por isso a configuração define typeAware: true. typeAware sozinho não ativa regras opcionais.
Incorreto
unknown já cobre string, então o constituinte string não restringe a união.
<script setup lang="ts">
type Redundant = unknown | string;
</script>
Correto
string e number são ambos constituintes úteis da união.
<script setup lang="ts">
type Redundant = string | number;
</script>
Configuração (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"type/no-redundant-type-constituents": "warn"
},
"typeAware": true
},
});
Depois, execute vp run lint.