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): contravariant generic default in ComponentOption #7369

Merged
merged 1 commit into from
Jan 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions types/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 16 additions & 4 deletions types/test/options-test.ts
Original file line number Diff line number Diff line change
@@ -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(""),
Expand Down Expand Up @@ -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', {
Expand Down