diff --git a/types/index.d.ts b/types/index.d.ts index a74a371484b..b0e24d767e9 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -15,6 +15,7 @@ export { ComponentOptions, FunctionalComponentOptions, RenderContext, + PropType, PropOptions, ComputedOptions, WatchHandler, diff --git a/types/options.d.ts b/types/options.d.ts index f6d92b97a16..dc37fa016bb 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -130,12 +130,14 @@ export interface RenderContext { injections: any } -export type Prop = { (): T } | { new (...args: any[]): T & object } +export type Prop = { (): T } | { new(...args: any[]): T & object } -export type PropValidator = PropOptions | Prop | Prop[]; +export type PropType = Prop | Prop[]; + +export type PropValidator = PropOptions | PropType; export interface PropOptions { - type?: Prop | Prop[]; + type?: PropType; required?: boolean; default?: T | null | undefined | (() => T | null | undefined); validator?(value: T): boolean; diff --git a/types/test/options-test.ts b/types/test/options-test.ts index ec06f9b8252..602be72d334 100644 --- a/types/test/options-test.ts +++ b/types/test/options-test.ts @@ -1,4 +1,4 @@ -import Vue, { VNode } from "../index"; +import Vue, { PropType, VNode } from "../index"; import { ComponentOptions, Component } from "../index"; import { CreateElement } from "../vue"; @@ -59,20 +59,36 @@ class Cat { private u = 1 } +interface IUser { + foo: string, + bar: number +} + +interface ICat { + foo: any, + bar: object +} + Vue.component('union-prop', { props: { - primitive: [String, Number], + cat: Object as PropType, + complexUnion: { type: [User, Number] as PropType }, + kittyUser: Object as PropType, + mixed: [RegExp, Array], object: [Cat, User], + primitive: [String, Number], regex: RegExp, - mixed: [RegExp, Array], - union: [User, Number] as {new(): User | Number}[] // requires annotation + union: [User, Number] as PropType }, data() { - this.primitive; + this.cat; + this.complexUnion; + this.kittyUser; + this.mixed; this.object; - this.union; + this.primitive; this.regex.compile; - this.mixed; + this.union; return { fixedSize: this.union, }