Skip to content

Hard/Impossible to find the right generic type for the wrapper (Vue3/TS/VTU2) #272

Closed
@TheDutchCoder

Description

@TheDutchCoder

Problem

When using a variable that you'll mount to later, the type for the variable is impossible to get for beginners of TS, leading to either no typings at all, or (worse) any typings on the wrapper.

Example

describe('Heading', () => {
  // People are probably able to see VueWrapper is needed here, but they don't know what the generic is supposed to be
  let wrapper

  beforeEach(() => {
    wrapper = mount(Heading)
  })
})

The following leads to no typings at all because of <any>

describe('Heading', () => {
  let wrapper: VueWrapper<any>

  beforeEach(() => {
    wrapper = mount(Heading)
  })
})

The correct generic is ComponentPublicInstance (in this case). But that doesn't show up in auto-complete and I found it pretty much just through trial and error.

describe('Heading', () => {
  let wrapper: VueWrapper<ComponentPublicInstance>

  beforeEach(() => {
    wrapper = mount(Heading)
  })
})

Solution

I really don't know enough about TS to offer any kind of help, but I think at least some directions in the documentation could help new users out that have been stuck on this issue.

My main grief with this has been the push for TS with Vue3, which I understand and even applaud. But then immediately getting stuck on pretty much the first step is quite deflating and I've seriously considered dropping TS just because I thought the eco-system (as delivered by vue-cli) simply wasn't ready yet.

Hope this helps and let me know if you guys need any more info!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions