TypeScript error for `@click` - Type '() => void' is not assignable to type 'undefined'
See original GitHub issueUpdated to VS Code 1.60 (TypeScript 4.4) today and started seeing these TS errors in my SFC’s:
<script setup lang="ts">
...
const onFilterBtnClick = () => windowOpen.value === 0 ? showWindow(3) : showWindow(0)
...
</script>
<template>
...
<ButtonFilter :window="windowOpen" @click="onFilterBtnClick" />
...
</template>
There were no issues when I worked on the project last week.
Full component: https://github.com/ttntm/recept0r-ts/blob/main/src/views/Home.vue
This TS error happens to any @click
attributes that are attached to components with props defined via TypeScript (as described here: https://v3.vuejs.org/api/sfc-script-setup.html#typescript-only-features):
@click
for components with TS props:(property) click: undefined
@click
for components without TS props:(property) click: ((...args: any[]) => any) | undefined
…copying that type definition into the button component’s defineProps
doesn’t make any difference; any type for property click
seems to be ignored.
Issue Analytics
- State:
- Created 2 years ago
- Comments:23 (5 by maintainers)
Top Results From Across the Web
Type '() => void' is not assignable to type '() => {}'
The back ground to the code is that I have a typescript class that is given a function and then stores it as...
Read more >Type 'void' is not assignable to type 'undefined'. #30880 - GitHub
It's for functions where the implementer is making no guarantees about the return type except that it won't be useful to callers. It's...
Read more >Incorrect "Type void is not assignable to type () => void" warning
I've checked this code in TypeScript , which doesn't produce an error: // script.ts type ScriptEvent = () => void; const scriptEvent: ScriptEvent...
Read more >Type 'void' is not assignable to type in TypeScript | bobbyhadz
The "Type 'void' is not assignable to type" TypeScript error occurs when we forget to return a value from a function, so the...
Read more >type 'void' is not assignable to type 'reactelement<any, any>
We explicitly set the function's return type to number but forgot to return a value, so TypeScript informs us that we must return...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This issue appears again on v1.0.3. This version has a few breaking changes e.g. this issue and also kebab-case prop
This issue will be fixed after we merge: https://github.com/vuejs/core/pull/6855