type/no-unsafe-assignment
Proibir atribuir valores any a alvos mais específicos.
| 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
anyValue é any e é atribuído a uma ligação anotada como number.
<script setup lang="ts">
declare const anyValue: any;
const assigned: number = anyValue;
</script>
Correto
A ligação é inicializada com o número 1.
<script setup lang="ts">
const assigned: number = 1;
</script>
Configuração (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"type/no-unsafe-assignment": "warn"
},
"typeAware": true
},
});
Depois, execute vp run lint.