question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript error for `@click` - Type '() => void' is not assignable to type 'undefined'

See original GitHub issue

Updated 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:closed
  • Created 2 years ago
  • Comments:23 (5 by maintainers)

github_iconTop GitHub Comments

16reactions
ldsenowcommented, Oct 11, 2022

This issue appears again on v1.0.3. This version has a few breaking changes e.g. this issue and also kebab-case prop

10reactions
xieyuhengcommented, Oct 14, 2022

This issue will be fixed after we merge: https://github.com/vuejs/core/pull/6855

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found