mirror of
https://gitee.com/vuejs/vue.git
synced 2024-11-30 02:57:43 +08:00
Fix definitons (#3591)
* Fix types * add “FunctionalComponentOptions” and “ContextObject” * fix and update types * Rename * Update vue.d.ts * Update options-test.ts
This commit is contained in:
parent
4061c42748
commit
8f4aab201b
23
types/options.d.ts
vendored
23
types/options.d.ts
vendored
@ -1,10 +1,12 @@
|
|||||||
import { Vue } from "./vue.d";
|
import { Vue } from "./vue.d";
|
||||||
import { VNode, VNodeDirective } from "./vnode.d";
|
import { VNode, VNodeData, VNodeDirective } from "./vnode.d";
|
||||||
|
|
||||||
type Constructor = {
|
type Constructor = {
|
||||||
new (...args: any[]): any;
|
new (...args: any[]): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type $createElement = typeof Vue.prototype.$createElement;
|
||||||
|
|
||||||
export interface ComponentOptions {
|
export interface ComponentOptions {
|
||||||
data?: Object | ( (this: Vue) => Object );
|
data?: Object | ( (this: Vue) => Object );
|
||||||
props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
|
props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
|
||||||
@ -15,7 +17,7 @@ export interface ComponentOptions {
|
|||||||
|
|
||||||
el?: Element | String;
|
el?: Element | String;
|
||||||
template?: string;
|
template?: string;
|
||||||
render?(createElement: typeof Vue.prototype.$createElement): VNode;
|
render?(createElement: $createElement): VNode;
|
||||||
staticRenderFns?: (() => VNode)[];
|
staticRenderFns?: (() => VNode)[];
|
||||||
|
|
||||||
beforeCreate?(): void;
|
beforeCreate?(): void;
|
||||||
@ -28,7 +30,7 @@ export interface ComponentOptions {
|
|||||||
updated?(): void;
|
updated?(): void;
|
||||||
|
|
||||||
directives?: { [key: string]: DirectiveOptions | DirectiveFunction };
|
directives?: { [key: string]: DirectiveOptions | DirectiveFunction };
|
||||||
components?: { [key: string]: ComponentOptions | typeof Vue };
|
components?: { [key: string]: ComponentOptions | FunctionalComponentOptions | typeof Vue };
|
||||||
transitions?: { [key: string]: Object };
|
transitions?: { [key: string]: Object };
|
||||||
filters?: { [key: string]: Function };
|
filters?: { [key: string]: Function };
|
||||||
|
|
||||||
@ -39,6 +41,21 @@ export interface ComponentOptions {
|
|||||||
delimiters?: [string, string];
|
delimiters?: [string, string];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FunctionalComponentOptions {
|
||||||
|
props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
|
||||||
|
functional: boolean;
|
||||||
|
render(this: never, createElement: $createElement, context: RenderContext): VNode;
|
||||||
|
name?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RenderContext {
|
||||||
|
props: any;
|
||||||
|
children: VNode[];
|
||||||
|
slots: any;
|
||||||
|
data: VNodeData;
|
||||||
|
parent: Vue;
|
||||||
|
}
|
||||||
|
|
||||||
export interface PropOptions {
|
export interface PropOptions {
|
||||||
type?: Constructor | Constructor[] | null;
|
type?: Constructor | Constructor[] | null;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import Vue = require("../index.d");
|
import Vue = require("../index.d");
|
||||||
import { ComponentOptions } from "../options.d";
|
import { ComponentOptions } from "../options.d";
|
||||||
|
import { FunctionalComponentOptions } from "../options.d";
|
||||||
|
|
||||||
interface Component extends Vue {
|
interface Component extends Vue {
|
||||||
a: number;
|
a: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Options: ComponentOptions = {
|
Vue.component('component', {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
a: 1
|
a: 1
|
||||||
@ -133,4 +134,17 @@ const Options: ComponentOptions = {
|
|||||||
name: "Component",
|
name: "Component",
|
||||||
extends: {} as ComponentOptions,
|
extends: {} as ComponentOptions,
|
||||||
delimiters: ["${", "}"]
|
delimiters: ["${", "}"]
|
||||||
}
|
} as ComponentOptions);
|
||||||
|
|
||||||
|
Vue.component('functional-component', {
|
||||||
|
props: ['prop'],
|
||||||
|
functional: true,
|
||||||
|
render(createElement, context) {
|
||||||
|
context.props;
|
||||||
|
context.children;
|
||||||
|
context.slots;
|
||||||
|
context.data;
|
||||||
|
context.parent;
|
||||||
|
return createElement("div", {}, context.children);
|
||||||
|
}
|
||||||
|
} as FunctionalComponentOptions);
|
||||||
|
16
types/vue.d.ts
vendored
16
types/vue.d.ts
vendored
@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
ComponentOptions,
|
ComponentOptions,
|
||||||
|
FunctionalComponentOptions,
|
||||||
WatchOptions,
|
WatchOptions,
|
||||||
WatchHandler,
|
WatchHandler,
|
||||||
DirectiveOptions,
|
DirectiveOptions,
|
||||||
@ -59,11 +60,20 @@ export declare class Vue {
|
|||||||
static set<T>(array: T[], key: number, value: T): T;
|
static set<T>(array: T[], key: number, value: T): T;
|
||||||
static delete(object: Object, key: string): void;
|
static delete(object: Object, key: string): void;
|
||||||
|
|
||||||
static directive(id: string, definition?: DirectiveOptions | DirectiveFunction): DirectiveOptions;
|
static directive(
|
||||||
|
id: string,
|
||||||
|
definition?: DirectiveOptions | DirectiveFunction
|
||||||
|
): DirectiveOptions;
|
||||||
static filter(id: string, definition?: Function): Function;
|
static filter(id: string, definition?: Function): Function;
|
||||||
static component(id: string, definition?: ComponentOptions | typeof Vue): typeof Vue;
|
static component(
|
||||||
|
id: string,
|
||||||
|
definition?: ComponentOptions | FunctionalComponentOptions | typeof Vue
|
||||||
|
): typeof Vue;
|
||||||
|
|
||||||
static use<T>(plugin: PluginObject<T> | PluginFunction<T>, options?: T): void;
|
static use<T>(plugin: PluginObject<T> | PluginFunction<T>, options?: T): void;
|
||||||
static mixin(mixin: typeof Vue | ComponentOptions): void;
|
static mixin(mixin: typeof Vue | ComponentOptions): void;
|
||||||
static compile(template: string): { render: Function, staticRenderFns: Function };
|
static compile(template: string): {
|
||||||
|
render(createElement: typeof Vue.prototype.$createElement): VNode;
|
||||||
|
staticRenderFns: (() => VNode)[];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user