type/no-unnecessary-type-arguments
Proibir argumentos de tipo iguais ao valor padrão.
| 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
O argumento explícito number é igual ao parâmetro de tipo padrão.
<script setup lang="ts">
function identity<T = number>(value: T): T {
return value;
}
const fromIdentity = identity<number>(1);
</script>
Correto
Chamar identity(1) deixa o parâmetro de tipo padrão valer.
<script setup lang="ts">
function identity<T = number>(value: T): T {
return value;
}
const fromIdentity = identity(1);
</script>
Configuração (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"type/no-unnecessary-type-arguments": "warn"
},
"typeAware": true
},
});
Depois, execute vp run lint.