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

fix(types): Fix mount and shallowMount types #254

Merged
merged 3 commits into from
Nov 23, 2020
Merged

fix(types): Fix mount and shallowMount types #254

merged 3 commits into from
Nov 23, 2020

Conversation

pikax
Copy link
Member

@pikax pikax commented Nov 21, 2020

fix #251

This was caused because vue-class-component dependency was not made optional or as a dev, so the import VueContructor would always be any, making all the mount and shallowMount to be caught by that overload.

I've removed the dependency on VueContructor on the mount, made it a bit more generic, this might break if the types changes on the vue-class-component (which I think is unlikely)

@ktsn can you just validate if this overload is enough?

// Class component - no props
export function mount<V>(
  originalComponent: {
    new (...args: any[]): V
    registerHooks(keys: string[]): void
  },
  options?: MountingOptions<any>
): VueWrapper<ComponentPublicInstance<V>>

// Class component - props
export function mount<V, P>(
  originalComponent: {
    new (...args: any[]): V
    props(Props: P): any
    registerHooks(keys: string[]): void
  },
  options?: MountingOptions<P>
): VueWrapper<ComponentPublicInstance<V>>

Comment on lines +84 to +91
export function mount<V, P>(
originalComponent: {
new (...args: any[]): V
props(Props: P): any
registerHooks(keys: string[]): void
},
options?: MountingOptions<P>
): VueWrapper<ComponentPublicInstance<V>>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function mount<V, P>(
originalComponent: {
new (...args: any[]): V
props(Props: P): any
registerHooks(keys: string[]): void
},
options?: MountingOptions<P>
): VueWrapper<ComponentPublicInstance<V>>
export function mount<V extends ComponentPublicInstance<P>, P>(
originalComponent: {
new (...args: any[]): V
},
options?: MountingOptions<P>
): VueWrapper<V>

As class component implements component public instance, just using the interface should be enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bit too lenient, because the defineComponent will also return a valid component public instance to be used on JSX

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, agree, having props intellisense is pretty cool. I don't think it's possible for data in class component though.

@lmiller1990
Copy link
Member

lmiller1990 commented Nov 23, 2020

@pikax is this good to go? Seems fine to me - are you still thinking about this typing or should we merge and release this?

@pikax
Copy link
Member Author

pikax commented Nov 23, 2020

@lmiller1990 I'm good with this typing

@lmiller1990 lmiller1990 merged commit 0b4f762 into vuejs:master Nov 23, 2020
@pikax pikax deleted the fix/class-component branch December 19, 2020 12:29
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

Successfully merging this pull request may close these issues.

Vue tsx component type definition 'any' in typescript project issue when unit-testing.
3 participants