type/require-typed-emits
Require type definition for defineEmits.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
happy-path, nuxt, ecosystem, 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
The array-only defineEmits(["save"]) declares the event name without a typed payload contract.
<script setup lang="ts">
defineEmits(["save"]);
</script>
Good
defineEmits<{ save: [] }>() declares the typed save event with an empty payload tuple, explicitly stating that it takes no payload arguments.
<script setup lang="ts">
defineEmits<{ save: [] }>();
</script>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"type/require-typed-emits": "warn"
},
"typeAware": true
},
});
Then run vp run lint.