@@ -65,6 +65,15 @@ interface ComponentOptionsWithProps<
65
65
setup ?: SetupFunction < Props , RawBindings > ;
66
66
}
67
67
68
+ interface ComponentOptionsWithArrayProps <
69
+ PropNames extends string = string ,
70
+ RawBindings = Data ,
71
+ Props = Readonly < { [ key in PropNames ] ?: any } >
72
+ > {
73
+ props ?: PropNames [ ] ;
74
+ setup ?: SetupFunction < Props , RawBindings > ;
75
+ }
76
+
68
77
interface ComponentOptionsWithoutProps < Props = unknown , RawBindings = Data > {
69
78
props ?: undefined ;
70
79
setup ?: SetupFunction < Props , RawBindings > ;
@@ -74,7 +83,20 @@ interface ComponentOptionsWithoutProps<Props = unknown, RawBindings = Data> {
74
83
export function defineComponent < RawBindings > (
75
84
options : ComponentOptionsWithoutProps < unknown , RawBindings >
76
85
) : VueProxy < unknown , RawBindings > ;
77
- // overload 2: object format with object props declaration
86
+ // overload 2: object format with array props declaration
87
+ // props inferred as { [key in PropNames]?: any }
88
+ // return type is for Vetur and TSX support
89
+ export function defineComponent <
90
+ PropNames extends string ,
91
+ RawBindings = Data ,
92
+ PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
93
+ > (
94
+ // prettier-ignore
95
+ options : (
96
+ ComponentOptionsWithArrayProps < PropNames , RawBindings > ) &
97
+ Omit < Vue2ComponentOptions < Vue > , keyof ComponentOptionsWithProps < never , never > >
98
+ ) : VueProxy < Readonly < { [ key in PropNames ] ?: any } > , RawBindings > ;
99
+ // overload 3: object format with object props declaration
78
100
// see `ExtractPropTypes` in ./componentProps.ts
79
101
export function defineComponent <
80
102
Props ,
@@ -94,12 +116,24 @@ export function defineComponent(options: any) {
94
116
return options as any ;
95
117
}
96
118
97
- // createComponent is kept around for retro-compatibility
98
119
// overload 1: object format with no props
99
120
export function createComponent < RawBindings > (
100
121
options : ComponentOptionsWithoutProps < unknown , RawBindings >
101
122
) : VueProxy < unknown , RawBindings > ;
102
- // overload 2: object format with object props declaration
123
+ // overload 2: object format with array props declaration
124
+ // props inferred as { [key in PropNames]?: any }
125
+ // return type is for Vetur and TSX support
126
+ export function createComponent <
127
+ PropNames extends string ,
128
+ RawBindings = Data ,
129
+ PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
130
+ > (
131
+ // prettier-ignore
132
+ options : (
133
+ ComponentOptionsWithArrayProps < PropNames , RawBindings > ) &
134
+ Omit < Vue2ComponentOptions < Vue > , keyof ComponentOptionsWithProps < never , never > >
135
+ ) : VueProxy < Readonly < { [ key in PropNames ] ?: any } > , RawBindings > ;
136
+ // overload 3: object format with object props declaration
103
137
// see `ExtractPropTypes` in ./componentProps.ts
104
138
export function createComponent <
105
139
Props ,
0 commit comments