From 57910723c6ba68386c15e095e42c1ed9603c7bcf Mon Sep 17 00:00:00 2001 From: Ferdy Budhidharma Date: Wed, 5 Dec 2018 16:50:13 -0600 Subject: [PATCH] feat(types): add Prop to main type declaration file (#6856) close #6850 --- types/index.d.ts | 1 + types/options.d.ts | 8 +++++--- types/test/options-test.ts | 30 +++++++++++++++++++++++------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index a74a3714..b0e24d76 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 a65f088b..d43b58d2 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -142,12 +142,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 b1ecf065..ce0e68de 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, }