Browse Source

feat(types): add Prop to main type declaration file (#6856)

close #6850
dev
Ferdy Budhidharma 6 years ago
committed by Evan You
parent
commit
57910723c6
  1. 1
      types/index.d.ts
  2. 8
      types/options.d.ts
  3. 30
      types/test/options-test.ts

1
types/index.d.ts

@ -15,6 +15,7 @@ export {
ComponentOptions,
FunctionalComponentOptions,
RenderContext,
PropType,
PropOptions,
ComputedOptions,
WatchHandler,

8
types/options.d.ts

@ -142,12 +142,14 @@ 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 }
export type PropValidator<T> = PropOptions<T> | Prop<T> | Prop<T>[];
export type PropType<T> = Prop<T> | Prop<T>[];
export type PropValidator<T> = PropOptions<T> | PropType<T>;
export interface PropOptions<T=any> {
type?: Prop<T> | Prop<T>[];
type?: PropType<T>;
required?: boolean;
default?: T | null | undefined | (() => T | null | undefined);
validator?(value: T): boolean;

30
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<ICat>,
complexUnion: { type: [User, Number] as PropType<User | number> },
kittyUser: Object as PropType<ICat & IUser>,
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<User | number>
},
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,
}

Loading…
Cancel
Save