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

Event type bug in template #1855

Closed
kingyue737 opened this issue Sep 11, 2022 · 3 comments · Fixed by #3588
Closed

Event type bug in template #1855

kingyue737 opened this issue Sep 11, 2022 · 3 comments · Fixed by #3588
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first

Comments

@kingyue737
Copy link
Contributor

kingyue737 commented Sep 11, 2022

Reproduction: https://github.com/kingyue737/volar-event-bug

  1. Clone the repo and run pnpm install
  2. Find the error in App.vue

image

Event event-any is defined with arg: any but volar thinks the type of handler should be (arg: string) => void
It seems this issue happens when one of the events has an argument typed as any

const emit = defineEmits<{
  (e: "event-any", arg: any): void;
  (e: "event-str", arg: string): void;
}>();

While volar extension shows ts error in template, vue-tsc doesn't complain about such issue.

Environment

  • Volar: 0.40.13
  • Vue: 2.7.10
  • VSCode: 1.71.0
  • Typescript: 4.8.3 (in takeover mode)
@xiaoxiangmoe xiaoxiangmoe added the bug Something isn't working label Sep 11, 2022
@edikdeisling
Copy link

edikdeisling commented Oct 12, 2022

Faced the issue too. There is a weird hack

const emit = defineEmits<{
  (e: "event-any", arg: any): void;
  (e: "__", arg: any): void; // this line fixes the issue
  (e: "event-str", arg: string): void;
}>();

@johnsoncodehk johnsoncodehk removed the help wanted Extra attention is needed label Feb 2, 2023
@johnsoncodehk johnsoncodehk added the good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first label Mar 18, 2023
@vidal7
Copy link

vidal7 commented May 3, 2023

@johnsoncodehk asked me to post my use case related to this issue.

In Vue 2.7, options API (defineComponent), TS 5, Volar 1.6.1, type of event is wrong in VSCode

image

It should have been

'event-without-payload': ($event?: undefined) => void

Also, it would have been nice that Volar throw a typescript error on handleEventWithPayload in the template has handleEventWithPayload does not satisfy the type (a: number, b: boolean) => void has defined in the p-component-issue

emits: {
            'event-without-payload': (): void => { },
            'event-with-payload': (a: number, b: boolean) => { }
        }

For reproduction repo, you can take the same as the issue 2742 (https://github.com/vidal7/volar-issue-2742)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants