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

Support Vue 2.7.16 #2087

Open
baboon-king opened this issue Dec 27, 2023 · 2 comments
Open

Support Vue 2.7.16 #2087

baboon-king opened this issue Dec 27, 2023 · 2 comments

Comments

@baboon-king
Copy link

Subject of the issue

Hi!
I doing this vuejs/create-vue#408

type definition not work with Vue 2.7.16

Steps to reproduce

  1. clone https://github.com/baboon-king/vue-test-utils-bug-miss-type-for-vue-2.7.16
  2. pnpm i
  3. pnpm run type-check
  4. focus terminal
xxxxx@XXXXXX-Air typescript-jsx-pinia-vitest-cypress % pnpm run type-check

> [email protected] type-check /Users/baboon/Downloads/create-vue-test/typescript-jsx-pinia-vitest-cypress
> vue-tsc --noEmit -p tsconfig.vitest.json --composite false

src/components/__tests__/HelloWorld.spec.ts:8:27 - error TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type 'ComponentPublicInstanceConstructor<Vue3Instance<{}, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{ msg: string; }>>>, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{ msg: string; }>>>, {}, {}, true, ComponentOptionsBase<...>> & ... 4 more ... & Readonly<...>, ... 4 more ..., MethodOptions> & Com...' is not assignable to parameter of type 'ExtendedVue<Vue<Record<string, any>, Record<string, any>, never, never, (event: string, ...args: any[]) => Vue<Record<string, any>, Record<string, any>, never, never, ...>>, ... 6 more ..., ComponentOptionsMixin>'.
      Type 'ComponentPublicInstanceConstructor<Vue3Instance<{}, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{ msg: string; }>>>, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{ msg: string; }>>>, {}, {}, true, ComponentOptionsBase<...>> & ... 4 more ... & Readonly<...>, ... 4 more ..., MethodOptions> & Com...' is missing the following properties from type 'VueConstructor<ExtractComputedReturns<{}> & DefaultProps & Vue<Record<string, any>, Record<string, any>, never, never, (event: string, ...args: any[]) => Vue<...>> & ShallowUnwrapRef<...> & Vue<...>>': extend, nextTick, set, delete, and 10 more.

8     const wrapper = mount(HelloWorld, { propsData: { msg: 'Hello Vitest' } })
                            ~~~~~~~~~~

  node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@vue/test-utils/types/index.d.ts:195:25
    195 export declare function mount<V extends Vue, Props = DefaultProps> (component: ExtendedVue<V, {}, {}, {}, Props>, options?: FunctionalComponentMountOptions<V>): Wrapper<CombinedVueInstance<V, {}, {}, {}, Props> & Vue>
                                ~~~~~
    The last overload is declared here.


Found 1 error in src/components/__tests__/HelloWorld.spec.ts:8

 ELIFECYCLE  Command failed with exit code 2.

Expected behaviour

worked

Actual behaviour

not worked

Possible Solution

I try install @vue/[email protected]. but it only work with Vue 3. see vuejs/test-utils#2289

so, That's why I came here.

@mohanyin
Copy link

Not an optimal solution, but I was able to work around this by patching the types:

import type { ComponentPublicInstanceConstructor } from 'vue/types/v3-component-public-instance';

...

declare module '@vue/test-utils' {
  export function mount<T extends ComponentPublicInstanceConstructor>(
    originalComponent: T,
    options?: ThisTypedMountOptions<Vue>
  ): Wrapper<Vue>;
}

@baboon-king
Copy link
Author

Not an optimal solution, but I was able to work around this by patching the types:

import type { ComponentPublicInstanceConstructor } from 'vue/types/v3-component-public-instance';

...

declare module '@vue/test-utils' {
  export function mount<T extends ComponentPublicInstanceConstructor>(
    originalComponent: T,
    options?: ThisTypedMountOptions<Vue>
  ): Wrapper<Vue>;
}

@mohanyin
Thank you, this is a good idea until the repository maintainer fixes the issue.
Truth be told, I think you can open a PR. 😇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants