-
Notifications
You must be signed in to change notification settings - Fork 245
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: vm should be properly typed #63
Conversation
I splitted the two fixes in 2 separate PRs:
|
5be170c
to
12d1929
Compare
Hey, thanks for helping out! Typing this correctly is something I am struggling with. I don't think this is entirely correct, though. const Foo = {
template: '<div>Foo</div>'
} Not everyone will use Full error:
🤔 |
I get your point. Maybe I can simply add an override, so people with |
The types have been tweaked to avoid the need of casting like `(wrapper.vm as any).msg`.
@lmiller1990 PTAL: I added a simple override instead of changing the signature. So everything works the same, but, if you use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one comment/question, thanks!
export function mount<T extends any>( | ||
originalComponent: any, | ||
options?: MountingOptions | ||
): VueWrapper<any> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @cexbrayat I will give this a quick test tmr and get it merged.
While we are here, can we get typings in the props
mounting options? I was able to do that in an experiment I built prior to this, found here
Eg then we could do
mount(Foo, {
props: {
bar: 'sadf' // <= can we get typesafety here? that would be cool as
}
})
If this is difficult to accomplish don't worry about it too much for now, but I agree, we should provide as many typings as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eg: component: new () => ComponentPublicInstance<P>
(or something)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll try to look into it soon, and I'll open a dedicated PR 👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lmiller1990 FYI I added some typings tests using tsd in #72 , improved the typing of vm some more in #73 and started working on properly typings the props options in #74
Awesome, love it. TS changed my life. I will do the next alpha when the oustanding PRs are merged in and the new Vue alpha comes out since we are waiting on a few bugfixes there. |
This is on top of #64
The types have been tweaked to avoid the need of casting like
(wrapper.vm as any).msg
.The test showcases the correct behavior: you can reproduce the issue by adding the test to the master banch. It will:
as any
castmsg
,isEnabled
fields andtoggle
function.