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

"vue-tsc" fails with "error TS2769: No overload matches this call" in "strict" mode #1973

Closed
tinobino opened this issue Feb 11, 2023 · 10 comments · Fixed by #2026
Closed

"vue-tsc" fails with "error TS2769: No overload matches this call" in "strict" mode #1973

tinobino opened this issue Feb 11, 2023 · 10 comments · Fixed by #2026
Labels
bug Something isn't working

Comments

@tinobino
Copy link

Describe the bug
vue-tsc fails with "error TS2769: No overload matches this call" in when "strict" mode is configured in "tsconfig.json".

If the defineEmits part in the component is removed vue-tsc doesn't complain. Seems that this issue is somehow related with Vue version 3.2.46.

To Reproduce
https://stackblitz.com/edit/vitest-dev-vitest-nwzj9x?file=components%2FSlotComponent.vue,test%2FSlotComponent.test.ts,package.json&initialPath=__vitest

Expected behavior
vue-tsc does not fail for the example given.

@tinobino tinobino added the bug Something isn't working label Feb 11, 2023
@cexbrayat
Copy link
Member

Hi @tinobino and thanks for the repro

After looking at your repro, it does look like there is an issue, but I don't know if that should be fixed in Vue core, VTU or Volar.

The error goes away if:

  • Vue v3.2.45 is used
  • if defineEmits is removed
  • More surprising, if <slot /> is removed from the template

Let me ping @johnsoncodehk as he may have some idea of what's going on

@johnsoncodehk
Copy link
Member

It seems due to DefineComponent type updates. It should fix if update this line:

export function mount<T extends DefineComponent<any, any, any, any>>(

- export declare function mount<T extends DefineComponent<any, any, any, any, any>>(component: T, options?: ComponentMountingOptions<T>): VueWrapper<InstanceType<T>>;
+ export declare function mount<T extends DefineComponent<any, any, any, any, any, any, any, any, any, any>>(component: T, options?: ComponentMountingOptions<T>): VueWrapper<InstanceType<T>>;

cexbrayat added a commit to cexbrayat/vue-test-utils-next that referenced this issue Feb 11, 2023
cexbrayat added a commit to cexbrayat/vue-test-utils-next that referenced this issue Feb 11, 2023
cexbrayat added a commit to cexbrayat/vue-test-utils-next that referenced this issue Feb 11, 2023
@cexbrayat
Copy link
Member

@johnsoncodehk Thanks for taking a look! Sadly, it doesn't look like it's fixing the issue
See #1974

@tinobino
Copy link
Author

Hi guys! Any updates on this? This issue prevents us from upgrade to latest vue version.

@cexbrayat
Copy link
Member

@johnsoncodehk kindly offered (on another channel) to refactor the types when he has time, so this issue will get fixed, but we can't give you a timeline.

In the meantime, you can still upgrade to the latest vue version, by adding an explication cast mount(SlotComponent as any, {...}). We understand this is not ideal, but that should unblock you to update

@spacedawwwg
Copy link

spacedawwwg commented Feb 28, 2023

I've added this to an test-utils.d.ts file for now and it seems to get us by without needing to modify all our test files and cast every component as any

// TODO: Remove once https://github.com/vuejs/test-utils/issues/1973 is resolved
declare module '@vue/test-utils' {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
  export function mount<T extends DefineComponent<{}, {}, any>>(
    component: T,
    options?: ComponentMountingOptions<T>
  ): VueWrapper<InstanceType<T>>;
}

@johnsoncodehk
Copy link
Member

I will check it out next week.

@dschmidt
Copy link

dschmidt commented Mar 27, 2023

I've added this to an test-utils.d.ts file for now and it seems to get us by without needing to modify all our test files and cast every component as any

// TODO: Remove once https://github.com/vuejs/test-utils/issues/1973 is resolved
declare module '@vue/test-utils' {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
  export function mount<T extends DefineComponent<{}, {}, any>>(
    component: T,
    options?: ComponentMountingOptions<T>
  ): VueWrapper<InstanceType<T>>;
}

Thanks, just a heads up: this should be put in a module file (i.e. with at least one top level export or import - in doubt add export {}) to make it a type augmentation, otherwise it replaces the module types completely and e.g. RouterLinkStub won't be available anymore.

@johnsoncodehk
Copy link
Member

Please track #2026

cexbrayat pushed a commit that referenced this issue Apr 15, 2023
This commit also drops node 14 from the build

The public signatures of `mount` and `renderToString` are now simplified, and should be more accurate.

Fixes #1973
cexbrayat added a commit to cexbrayat/vue-test-utils-next that referenced this issue Apr 15, 2023
cexbrayat added a commit that referenced this issue Apr 15, 2023
@cexbrayat
Copy link
Member

Thanks to @johnsoncodehk , the issue should be fixed in the next release (I added a test based on @tinobino repro to make sure we don't have this again).

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

Successfully merging a pull request may close this issue.

5 participants