Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromvuejs/vue

Commit144bf5a

Browse files
HerringtonDarkholmeyyx990803
authored andcommitted
fix(types): prefer normal component over functional one (vuejs#7687)
1 parent68b51f2 commit144bf5a

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

‎types/options.d.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,21 @@ export type Accessors<T> = {
3131
[KinkeyofT]:(()=>T[K])|ComputedOptions<T[K]>
3232
}
3333

34+
typeDataDef<Data,Props,V>=Data|((this:Readonly<Props>&V)=>Data)
3435
/**
3536
* This type should be used when an array of strings is used for a component's `props` value.
3637
*/
3738
exporttypeThisTypedComponentOptionsWithArrayProps<VextendsVue,Data,Methods,Computed,PropNamesextendsstring>=
3839
object&
39-
ComponentOptions<V,Data|((this:Readonly<Record<PropNames,any>>&V)=>Data),Methods,Computed,PropNames[]>&
40+
ComponentOptions<V,DataDef<Data,Record<PropNames,any>,V>,Methods,Computed,PropNames[],Record<PropNames,any>>&
4041
ThisType<CombinedVueInstance<V,Data,Methods,Computed,Readonly<Record<PropNames,any>>>>;
4142

4243
/**
4344
* This type should be used when an object mapped to `PropOptions` is used for a component's `props` value.
4445
*/
4546
exporttypeThisTypedComponentOptionsWithRecordProps<VextendsVue,Data,Methods,Computed,Props>=
4647
object&
47-
ComponentOptions<V,Data|((this:Readonly<Props>&V)=>Data),Methods,Computed,RecordPropsDefinition<Props>>&
48+
ComponentOptions<V,DataDef<Data,Props,V>,Methods,Computed,RecordPropsDefinition<Props>,Props>&
4849
ThisType<CombinedVueInstance<V,Data,Methods,Computed,Readonly<Props>>>;
4950

5051
typeDefaultData<V>=object|((this:V)=>object);
@@ -56,7 +57,8 @@ export interface ComponentOptions<
5657
Data=DefaultData<V>,
5758
Methods=DefaultMethods<V>,
5859
Computed=DefaultComputed,
59-
PropsDef=PropsDefinition<DefaultProps>>{
60+
PropsDef=PropsDefinition<DefaultProps>,
61+
Props=DefaultProps>{
6062
data?:Data;
6163
props?:PropsDef;
6264
propsData?:object;
@@ -66,7 +68,8 @@ export interface ComponentOptions<
6668

6769
el?:Element|string;
6870
template?:string;
69-
render?(createElement:CreateElement):VNode;
71+
// hack is for funcitonal component type inference, should not used in user code
72+
render?(createElement:CreateElement,hack:RenderContext<Props>):VNode;
7073
renderError?:(h:()=>VNode,err:Error)=>VNode;
7174
staticRenderFns?:((createElement:CreateElement)=>VNode)[];
7275

‎types/vue.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ export interface VueConstructor<V extends Vue = Vue> {
8282
new<Data=object,Methods=object,Computed=object,Props=object>(options?:ThisTypedComponentOptionsWithRecordProps<V,Data,Methods,Computed,Props>):CombinedVueInstance<V,Data,Methods,Computed,Record<keyofProps,any>>;
8383
new(options?:ComponentOptions<V>):CombinedVueInstance<V,object,object,object,Record<keyofobject,any>>;
8484

85-
extend<PropNamesextendsstring=never>(definition:FunctionalComponentOptions<Record<PropNames,any>,PropNames[]>):ExtendedVue<V,{},{},{},Record<PropNames,any>>;
86-
extend<Props>(definition:FunctionalComponentOptions<Props,RecordPropsDefinition<Props>>):ExtendedVue<V,{},{},{},Props>;
8785
extend<Data,Methods,Computed,PropNamesextendsstring=never>(options?:ThisTypedComponentOptionsWithArrayProps<V,Data,Methods,Computed,PropNames>):ExtendedVue<V,Data,Methods,Computed,Record<PropNames,any>>;
8886
extend<Data,Methods,Computed,Props>(options?:ThisTypedComponentOptionsWithRecordProps<V,Data,Methods,Computed,Props>):ExtendedVue<V,Data,Methods,Computed,Props>;
87+
extend<PropNamesextendsstring=never>(definition:FunctionalComponentOptions<Record<PropNames,any>,PropNames[]>):ExtendedVue<V,{},{},{},Record<PropNames,any>>;
88+
extend<Props>(definition:FunctionalComponentOptions<Props,RecordPropsDefinition<Props>>):ExtendedVue<V,{},{},{},Props>;
8989
extend(options?:ComponentOptions<V>):ExtendedVue<V,{},{},{},{}>;
9090

9191
nextTick(callback:()=>void,context?:any[]):void;
@@ -104,10 +104,10 @@ export interface VueConstructor<V extends Vue = Vue> {
104104
component(id:string):VueConstructor;
105105
component<VCextendsVueConstructor>(id:string,constructor:VC):VC;
106106
component<Data,Methods,Computed,Props>(id:string,definition:AsyncComponent<Data,Methods,Computed,Props>):ExtendedVue<V,Data,Methods,Computed,Props>;
107-
component<PropNamesextendsstring>(id:string,definition:FunctionalComponentOptions<Record<PropNames,any>,PropNames[]>):ExtendedVue<V,{},{},{},Record<PropNames,any>>;
108-
component<Props>(id:string,definition:FunctionalComponentOptions<Props,RecordPropsDefinition<Props>>):ExtendedVue<V,{},{},{},Props>;
109107
component<Data,Methods,Computed,PropNamesextendsstring=never>(id:string,definition?:ThisTypedComponentOptionsWithArrayProps<V,Data,Methods,Computed,PropNames>):ExtendedVue<V,Data,Methods,Computed,Record<PropNames,any>>;
110108
component<Data,Methods,Computed,Props>(id:string,definition?:ThisTypedComponentOptionsWithRecordProps<V,Data,Methods,Computed,Props>):ExtendedVue<V,Data,Methods,Computed,Props>;
109+
component<PropNamesextendsstring>(id:string,definition:FunctionalComponentOptions<Record<PropNames,any>,PropNames[]>):ExtendedVue<V,{},{},{},Record<PropNames,any>>;
110+
component<Props>(id:string,definition:FunctionalComponentOptions<Props,RecordPropsDefinition<Props>>):ExtendedVue<V,{},{},{},Props>;
111111
component(id:string,definition?:ComponentOptions<V>):ExtendedVue<V,{},{},{},{}>;
112112

113113
use<T>(plugin:PluginObject<T>|PluginFunction<T>,options?:T):void;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp