Vize

type/no-unsafe-argument

Proibir chamar uma função com um valor do tipo any.

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 é passado a um parâmetro que espera number.

<script setup lang="ts">
declare const anyValue: any;
function takesNumber(value: number): number {
  return value;
}
takesNumber(anyValue);
</script>

Correto

A chamada passa o número 1 ao parâmetro number.

<script setup lang="ts">
function takesNumber(value: number): number {
  return value;
}
takesNumber(1);
</script>

Configuração (Vite+)

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

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "type/no-unsafe-argument": "warn"
    },
    "typeAware": true
  },
});

Depois, execute vp run lint.

Páginas relacionadas