From f1c1db9acee744f0d753ad7fa9b2ff2d4c24d435 Mon Sep 17 00:00:00 2001 From: Herrington Darkholme Date: Fri, 9 Mar 2018 02:55:52 +0800 Subject: [PATCH] fix(types): prefer normal component over functional one (#7687) --- types/options.d.ts | 11 +++++++---- types/vue.d.ts | 8 ++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/types/options.d.ts b/types/options.d.ts index 6b5ebe41726..cc58affe6a1 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -31,12 +31,13 @@ export type Accessors = { [K in keyof T]: (() => T[K]) | ComputedOptions } +type DataDef = Data | ((this: Readonly & V) => Data) /** * This type should be used when an array of strings is used for a component's `props` value. */ export type ThisTypedComponentOptionsWithArrayProps = object & - ComponentOptions> & V) => Data), Methods, Computed, PropNames[]> & + ComponentOptions, V>, Methods, Computed, PropNames[], Record> & ThisType>>>; /** @@ -44,7 +45,7 @@ export type ThisTypedComponentOptionsWithArrayProps = object & - ComponentOptions & V) => Data), Methods, Computed, RecordPropsDefinition> & + ComponentOptions, Methods, Computed, RecordPropsDefinition, Props> & ThisType>>; type DefaultData = object | ((this: V) => object); @@ -56,7 +57,8 @@ export interface ComponentOptions< Data=DefaultData, Methods=DefaultMethods, Computed=DefaultComputed, - PropsDef=PropsDefinition> { + PropsDef=PropsDefinition, + Props=DefaultProps> { data?: Data; props?: PropsDef; propsData?: object; @@ -66,7 +68,8 @@ export interface ComponentOptions< el?: Element | string; template?: string; - render?(createElement: CreateElement): VNode; + // hack is for funcitonal component type inference, should not used in user code + render?(createElement: CreateElement, hack: RenderContext): VNode; renderError?: (h: () => VNode, err: Error) => VNode; staticRenderFns?: ((createElement: CreateElement) => VNode)[]; diff --git a/types/vue.d.ts b/types/vue.d.ts index 045644e0a94..e0b29157cfa 100644 --- a/types/vue.d.ts +++ b/types/vue.d.ts @@ -82,10 +82,10 @@ export interface VueConstructor { new (options?: ThisTypedComponentOptionsWithRecordProps): CombinedVueInstance>; new (options?: ComponentOptions): CombinedVueInstance>; - extend(definition: FunctionalComponentOptions, PropNames[]>): ExtendedVue>; - extend(definition: FunctionalComponentOptions>): ExtendedVue; extend(options?: ThisTypedComponentOptionsWithArrayProps): ExtendedVue>; extend(options?: ThisTypedComponentOptionsWithRecordProps): ExtendedVue; + extend(definition: FunctionalComponentOptions, PropNames[]>): ExtendedVue>; + extend(definition: FunctionalComponentOptions>): ExtendedVue; extend(options?: ComponentOptions): ExtendedVue; nextTick(callback: () => void, context?: any[]): void; @@ -104,10 +104,10 @@ export interface VueConstructor { component(id: string): VueConstructor; component(id: string, constructor: VC): VC; component(id: string, definition: AsyncComponent): ExtendedVue; - component(id: string, definition: FunctionalComponentOptions, PropNames[]>): ExtendedVue>; - component(id: string, definition: FunctionalComponentOptions>): ExtendedVue; component(id: string, definition?: ThisTypedComponentOptionsWithArrayProps): ExtendedVue>; component(id: string, definition?: ThisTypedComponentOptionsWithRecordProps): ExtendedVue; + component(id: string, definition: FunctionalComponentOptions, PropNames[]>): ExtendedVue>; + component(id: string, definition: FunctionalComponentOptions>): ExtendedVue; component(id: string, definition?: ComponentOptions): ExtendedVue; use(plugin: PluginObject | PluginFunction, options?: T): void;