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

Return type confusing, generics not working #2314

Closed
philly-vanilly opened this issue Jan 24, 2024 · 2 comments
Closed

Return type confusing, generics not working #2314

philly-vanilly opened this issue Jan 24, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@philly-vanilly
Copy link

philly-vanilly commented Jan 24, 2024

const wrapper: ReturnType<typeof mount<SomeComponent>> = mount(SomeComponent);

This is giving me the error ComponentPublicInstance<{}, Omit<{ value: string; }, never>> is not assignable to type
ComponentPublicInstance<NonNullable<Partial<{}> & Omit<{} & VNodeProps & AllowedComponentProps & ComponentCustomProps & Readonly<ExtractPropTypes<{}>>, never>>, { ...; } & ... 6 more ... & Omit<...>>

What am I doing wrong? The type can of course be resolved automatically, but only if you directly assing it to. constant. if you want to have a wrapper defined but not immediately assigned (which happens later in beforeEach), this leads to type errors.

I guess the best practices are to not create the wrapper in beforeEach but in each test (?), but I have over 300 test-suites in a project I did not set up myself and I need to improve the type-safety without refactoring them all. I do not want ot use "any" for this.

@philly-vanilly philly-vanilly added the bug Something isn't working label Jan 24, 2024
@cexbrayat
Copy link
Member

Hi @philly-vanilly

Yes this is something we hope to improve. There is a WIP PR that you can track : see #2242 Some things need to change in Vue itself as well.

I usually don't use a shared wrapper between my tests. I create it in each test, and let TS infer the return type.

function navbarWrapper() {
  return mount(Navbar, {
    // options
  });
}

describe('Navbar.vue', () => {
  test('something', () => {
    const wrapper = navbarWrapper();
  })
});

@philly-vanilly
Copy link
Author

@cexbrayat Ok thank you, I figured this is the best way, good to hear it from a pro too. I will keep track of the issue

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