Vize

script/require-typed-ref

Require an explicit type argument on a ref() initialized with no value, null, or undefined

Bad · Good

Default severity: warning
Presets: none
Automatic fix: None; review the suggested change
Applies to: JS/TS scripts in Vue SFCs; examples show the relevant Options API or script setup form
Options: No rule-specific options. Severity and preset selection are configurable.

Configuration (Vite+)

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

export default defineConfig({
  lint: {
    vize: {
      "preset": "incremental",
      "rules": {
        "script/require-typed-ref": "warn"
      }
    },
  },
});
vp run lint

Bad

The imported ref calls have neither a type argument nor a useful initial value: no argument, null, and undefined cannot infer the intended future value type.

<script setup lang="ts">
import { ref } from 'vue'

const a = ref()           // Ref<undefined>
const b = ref(null)       // Ref<null>
const c = ref(undefined)  // Ref<undefined>
</script>

Good

Explicit type arguments describe the string and nullable User refs. ref(0) already has a concrete numeric initializer and can rely on inference.

<script setup lang="ts">
import { ref } from 'vue'

const a = ref<string>()
const b = ref<User | null>(null)
const c = ref(0)          // inferred Ref<number>
</script>

Good avoids this rule's finding under the configuration above; other rules may still report diagnostics.

Implementation · All rules