Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emitter always have $event: any by default even it is defined with no parameter attached #270

Closed
cuongvuong-phoenix opened this issue Jun 16, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@cuongvuong-phoenix
Copy link

cuongvuong-phoenix commented Jun 16, 2021

Reproduction

Assume we have 2 componens defined like following:

<!-- Child.vue -->
<template>
  <button @click="emit('onClick')">Click me</button>
</template>

<script setup lang="ts">
  import { defineEmit } from 'vue';
  
  const emit = defineEmit({
    // No parameter declared.
    onClick: () => true,
  });
</script>
<!-- Parent.vue -->
<template>
  <div>
    <Child @on-click="onChildClick()" />
  </div>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import Child from './Child.vue';
  
  const counter = ref(0);
  
  function onChildClick() {
    counter.value++;
    console.log(`Clicked ${counter.value} times`);
  }
</script>

Both Volar and vue-tsc throw this error at event listener:

src/components/Parent.vue:4:13 - error TS2322: Type '($event: any) => void' is not assignable to type '() => void'.

4     <Child @on-click="onChildClick()" />

Expected Result

No error is thrown.

@cuongvuong-phoenix cuongvuong-phoenix changed the title Emitter parameters type always have $event: any by default Emitter always have $event: any by default even it is defined with no parameter attached Jun 16, 2021
@johnsoncodehk johnsoncodehk added the bug Something isn't working label Jun 17, 2021
@johnsoncodehk johnsoncodehk added design limitation enhancement New feature or request bug Something isn't working and removed bug Something isn't working design limitation enhancement New feature or request labels Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants