Skip to content

Commit df4af4b

Browse files
pikaxyyx990803
authored andcommittedMar 19, 2019
fix(types): allow using functions on the PropTypes (#9733)
close #9692
1 parent 22790b2 commit df4af4b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
 

‎types/options.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export interface RenderContext<Props=DefaultProps> {
144144
injections: any
145145
}
146146

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

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

‎types/test/options-test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ interface ICat {
6868
foo: any,
6969
bar: object
7070
}
71+
type ConfirmCallback = (confirm: boolean) => void;
7172

7273
Vue.component('union-prop', {
7374
props: {
7475
cat: Object as PropType<ICat>,
7576
complexUnion: { type: [User, Number] as PropType<User | number> },
7677
kittyUser: Object as PropType<ICat & IUser>,
78+
callback: Function as PropType<ConfirmCallback>,
7779
mixed: [RegExp, Array],
7880
object: [Cat, User],
7981
primitive: [String, Number],
@@ -84,6 +86,7 @@ Vue.component('union-prop', {
8486
this.cat;
8587
this.complexUnion;
8688
this.kittyUser;
89+
this.callback(true);
8790
this.mixed;
8891
this.object;
8992
this.primitive;
@@ -281,6 +284,18 @@ Vue.component('component', {
281284
delimiters: ["${", "}"]
282285
});
283286

287+
288+
Vue.component('custom-prop-type-function', {
289+
props: {
290+
callback: Function as PropType<(confirm: boolean) => void>,
291+
},
292+
methods: {
293+
confirm(){
294+
this.callback(true);
295+
}
296+
}
297+
});
298+
284299
Vue.component('provide-inject', {
285300
provide: {
286301
foo: 1

0 commit comments

Comments
 (0)
Please sign in to comment.