Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export {
ComponentOptions,
FunctionalComponentOptions,
RenderContext,
PropType,
PropOptions,
ComputedOptions,
WatchHandler,
Expand Down
6 changes: 4 additions & 2 deletions types/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ 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>[];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the type here be PropType<T>?

Expand Down
30 changes: 23 additions & 7 deletions types/test/options-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Vue from "../index";
import Vue, { PropType } from "../index";
import { AsyncComponent, ComponentOptions, FunctionalComponentOptions } from "../index";
import { CreateElement } from "../vue";

Expand Down Expand Up @@ -47,20 +47,36 @@ class Cat {
private u: number
}

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,
}
Expand Down