Browse Source

fix(types): contravariant generic default in ComponentOption (#7369)

dev
Herrington Darkholme 7 years ago
committed by Evan You
parent
commit
6ee684983b
  1. 7
      types/options.d.ts
  2. 20
      types/test/options-test.ts

7
types/options.d.ts

@ -6,16 +6,17 @@ type Constructor = {
}
// we don't support infer props in async component
export type Component<Data=DefaultData<Vue>, Methods=DefaultMethods<Vue>, Computed=DefaultComputed, Props=DefaultProps> =
// N.B. ComponentOptions<V> is contravariant, the default generic should be bottom type
export type Component<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> =
| typeof Vue
| FunctionalComponentOptions<Props>
| ComponentOptions<Vue, Data, Methods, Computed, Props>
| ComponentOptions<never, Data, Methods, Computed, Props>
interface EsModuleComponent {
default: Component
}
export type AsyncComponent<Data=DefaultData<Vue>, Methods=DefaultMethods<Vue>, Computed=DefaultComputed, Props=DefaultProps> = (
export type AsyncComponent<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> = (
resolve: (component: Component<Data, Methods, Computed, Props>) => void,
reject: (reason?: any) => void
) => Promise<Component | EsModuleComponent> | void;

20
types/test/options-test.ts

@ -1,11 +1,23 @@
import Vue, { VNode } from "../index";
import { AsyncComponent, ComponentOptions, FunctionalComponentOptions } from "../index";
import { AsyncComponent, ComponentOptions, FunctionalComponentOptions, Component } from "../index";
import { CreateElement } from "../vue";
interface Component extends Vue {
interface MyComponent extends Vue {
a: number;
}
const option: ComponentOptions<MyComponent> = {
data() {
return {
a: 123
}
}
}
// contravariant generic should use never
const anotherOption: ComponentOptions<never> = option
const componentType: Component = option
Vue.component('sub-component', {
components: {
a: Vue.component(""),
@ -41,10 +53,10 @@ Vue.component('string-prop', {
});
class User {
private u: number
private u = 1
}
class Cat {
private u: number
private u = 1
}
Vue.component('union-prop', {

Loading…
Cancel
Save