type/no-reactivity-loss
Disallow plain snapshots of reactive values across assignments and calls.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
nuxt, opinionated |
No | None |
Applies to: Type information in Vue SFC scripts and templates, for the constructs shown below.
This rule reads type information from your TypeScript project (tsconfig.json), so the configuration sets typeAware: true. typeAware does not turn on opt-in rules by itself.
Bad
const count = state.count takes a plain numeric snapshot of the reactive property, so later updates of state.count are not reflected in that binding.
<script setup lang="ts">
import { reactive } from "vue";
const state = reactive({ count: 0 });
const count = state.count;
</script>
Good
toRef(state, "count") keeps count linked to the original reactive property rather than copying its current primitive value.
<script setup lang="ts">
import { reactive, toRef } from "vue";
const state = reactive({ count: 0 });
const count = toRef(state, "count");
</script>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"type/no-reactivity-loss": "warn"
},
"typeAware": true
},
});
Then run vp run lint.