From 4abc845a5b054c2c431a6151986c5092e8e04911 Mon Sep 17 00:00:00 2001 From: Ferdy Budhidharma Date: Thu, 19 Oct 2017 07:57:59 -0500 Subject: [PATCH 1/3] feat: add Prop to main type declaration file --- types/index.d.ts | 1 + types/test/options-test.ts | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index da58517f42f..92593a7c53d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -12,6 +12,7 @@ export { ComponentOptions, FunctionalComponentOptions, RenderContext, + Prop, PropOptions, ComputedOptions, WatchHandler, diff --git a/types/test/options-test.ts b/types/test/options-test.ts index e7cd8bacdab..bb0ca9bce02 100644 --- a/types/test/options-test.ts +++ b/types/test/options-test.ts @@ -1,4 +1,4 @@ -import Vue from "../index"; +import Vue, { Prop } from "../index"; import { AsyncComponent, ComponentOptions, FunctionalComponentOptions } from "../index"; import { CreateElement } from "../vue"; @@ -47,8 +47,19 @@ class Cat { private u: number } +interface IFoo { + foo: string, + bar: number +} + +interface IBar { + foo: any, + bar: object +} + Vue.component('union-prop', { props: { + customInterface: [Object as Prop, Object as Prop], primitive: [String, Number], object: [Cat, User], regex: RegExp, @@ -56,6 +67,7 @@ Vue.component('union-prop', { union: [User, Number] as {new(): User | Number}[] // requires annotation }, data() { + this.customInterface; this.primitive; this.object; this.union; From 70cdd06636a8572a69e766f261192ff777db2f3b Mon Sep 17 00:00:00 2001 From: Ferdy Budhidharma Date: Fri, 20 Oct 2017 13:08:23 -0500 Subject: [PATCH 2/3] fix: use new PropType instead of Prop for exported types --- types/index.d.ts | 2 +- types/options.d.ts | 6 ++++-- types/test/options-test.ts | 26 +++++++++++++++----------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 92593a7c53d..9b5c07b67f4 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -12,7 +12,7 @@ export { ComponentOptions, FunctionalComponentOptions, RenderContext, - Prop, + PropType, PropOptions, ComputedOptions, WatchHandler, diff --git a/types/options.d.ts b/types/options.d.ts index c4d822f69ef..3d8975244cc 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -122,9 +122,11 @@ 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[]; diff --git a/types/test/options-test.ts b/types/test/options-test.ts index bb0ca9bce02..f9ccd6fc7ba 100644 --- a/types/test/options-test.ts +++ b/types/test/options-test.ts @@ -1,4 +1,4 @@ -import Vue, { Prop } from "../index"; +import Vue, { PropType } from "../index"; import { AsyncComponent, ComponentOptions, FunctionalComponentOptions } from "../index"; import { CreateElement } from "../vue"; @@ -47,32 +47,36 @@ class Cat { private u: number } -interface IFoo { +interface IUser { foo: string, bar: number } -interface IBar { +interface ICat { foo: any, bar: object } Vue.component('union-prop', { props: { - customInterface: [Object as Prop, Object as Prop], - 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.customInterface; - 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, } From 561b18e12a9dccbab5796139395cbe6f9a802412 Mon Sep 17 00:00:00 2001 From: Ferdy Budhidharma Date: Tue, 27 Mar 2018 14:57:06 -0500 Subject: [PATCH 3/3] fix(prop-type): reuse generic PropType type --- types/options.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/options.d.ts b/types/options.d.ts index a67e3adda70..3c478e50de9 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -133,7 +133,7 @@ export type PropType = Prop | Prop[]; export type PropValidator = PropOptions | PropType; export interface PropOptions { - type?: Prop | Prop[]; + type?: PropType; required?: boolean; default?: T | null | undefined | (() => object); validator?(value: T): boolean;