script/require-function-return-type
Require return type annotations on functions.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
None | No | None |
Applies to: JS/TS scripts in Vue SFCs; examples show the relevant Options API or script setup form.
Bad
Both add and greet annotate their parameters but omit a return-type annotation; inferred returns do not satisfy this explicit-annotation policy.
<script setup lang="ts">
const add = (a: number, b: number) => {
return a + b
}
function greet(name: string) {
return `Hello, ${name}`
}
</script>
Good
add declares : number, and greet declares : string, making the return contracts explicit without changing either body.
<script setup lang="ts">
const add = (a: number, b: number): number => {
return a + b
}
function greet(name: string): string {
return `Hello, ${name}`
}
</script>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"script/require-function-return-type": "warn"
}
},
});
Then run vp run lint.