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): make compatible with Vue 2.5 and TypeScript 2.6 #317

Merged
merged 4 commits into from
Jan 3, 2018
Merged

fix(types): make compatible with Vue 2.5 and TypeScript 2.6 #317

merged 4 commits into from
Jan 3, 2018

Conversation

ktsn
Copy link
Member

@ktsn ktsn commented Jan 1, 2018

fix #272

There are two reasons that the types test is broken:

  1. The 1st type parameter of ComponentOptions is no longer specify the this type of lifecycle hooks because Vue 2.5 uses the intersection type with ThisType to do that.
  2. TypeScript 2.6 had introduced more strict type checking for function types. So the Component type cannot pass the type checking.

I've added ThisTyped version of MountOptions and ShallowOptions to solve 1. Also added a new Component type to solve 2.

@ktsn
Copy link
Member Author

ktsn commented Jan 1, 2018

I'm not sure why the unit test failed 😕
Maybe bumping to Vue 2.5 affects the behavior of find?

types/index.d.ts Outdated
import Vue, { VNodeData, Component, ComponentOptions, FunctionalComponentOptions } from 'vue'
import Vue, { VNodeData, ComponentOptions, FunctionalComponentOptions } from 'vue'

export type Component =
Copy link
Member

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?

Copy link
Member Author

@ktsn ktsn Jan 2, 2018

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 {}?

Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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

Copy link
Member Author

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.

@eddyerburgh eddyerburgh merged commit fad069d into vuejs:dev Jan 3, 2018
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.

Types test broken in Vue 2.5.x
3 participants