-
Notifications
You must be signed in to change notification settings - Fork 668
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): make compatible with Vue 2.5 and TypeScript 2.6 #317
Conversation
I'm not sure why the unit test failed 😕 |
types/index.d.ts
Outdated
import Vue, { VNodeData, Component, ComponentOptions, FunctionalComponentOptions } from 'vue' | ||
import Vue, { VNodeData, ComponentOptions, FunctionalComponentOptions } from 'vue' | ||
|
||
export type Component = |
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.
If Component
type from vue package fails, it probably means we need to fix it in the main repo. Would you like to point out the failing usage?
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.
Indeed. I found the Component
type always has the base Vue
type for this
type of Data
and Method
in default. That fails type checking if ComponentOptions
has different type: https://github.com/vuejs/vue-test-utils/blob/dev/types/test/resources.ts#L9
Maybe we should change the default type parameters of Component
(and AsyncComponent
) to {}
?
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.
Shall we merge this now and update the Component type here later when it's fixed in the main repo?
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.
Let's merge it now. We can change it later after new Vue is released.
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.
@ktsn The problem is that Component
isn't correctly setting up type bound.
ComponentOption<V>
is contravariant, that is, ComponentOption<Normal>
isn't a sub type of ComponentOption<Vue>
, but of ComponentOption<never>
.
beforeCreate
in componentOption would also break assignment here if contravariant method was checked. But currently it is not https://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#note
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.
@HerringtonDarkholme Thanks for clarify the problem! I didn't realize we can use never
for the default generic type.
I'll change the ComponentOptions
's 1st type parameter to never
for now before this PR is merged.
fix #272
There are two reasons that the types test is broken:
ComponentOptions
is no longer specify thethis
type of lifecycle hooks because Vue 2.5 uses the intersection type withThisType
to do that.Component
type cannot pass the type checking.I've added
ThisType
d version ofMountOptions
andShallowOptions
to solve 1. Also added a newComponent
type to solve 2.