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): allow using functions on the PropTypes (#9692) #9733

Merged
merged 2 commits into from Mar 19, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion types/options.d.ts
Expand Up @@ -144,7 +144,7 @@ export interface RenderContext<Props=DefaultProps> {
injections: any
}

export type Prop<T> = { (): T } | { new(...args: any[]): T & object }
export type Prop<T> = { (): T } | { new(...args: any[]): T & object } | { new(...args: string[]): Function }

export type PropType<T> = Prop<T> | Prop<T>[];

Expand Down
15 changes: 15 additions & 0 deletions types/test/options-test.ts
Expand Up @@ -68,12 +68,14 @@ interface ICat {
foo: any,
bar: object
}
type ConfirmCallback = (confirm: boolean) => void;

Vue.component('union-prop', {
props: {
cat: Object as PropType<ICat>,
complexUnion: { type: [User, Number] as PropType<User | number> },
kittyUser: Object as PropType<ICat & IUser>,
callback: Function as PropType<ConfirmCallback>,
mixed: [RegExp, Array],
object: [Cat, User],
primitive: [String, Number],
Expand All @@ -84,6 +86,7 @@ Vue.component('union-prop', {
this.cat;
this.complexUnion;
this.kittyUser;
this.callback(true);
this.mixed;
this.object;
this.primitive;
Expand Down Expand Up @@ -281,6 +284,18 @@ Vue.component('component', {
delimiters: ["${", "}"]
});


Vue.component('custom-prop-type-function', {
props: {
callback: Function as PropType<(confirm: boolean) => void>,
},
methods: {
confirm(){
this.callback(true);
}
}
});

Vue.component('provide-inject', {
provide: {
foo: 1
Expand Down