File tree Expand file tree Collapse file tree 3 files changed +43
-10
lines changed Expand file tree Collapse file tree 3 files changed +43
-10
lines changed Original file line number Diff line number Diff line change @@ -68,11 +68,18 @@ export type ObjectEmitsOptions = Record<
68
68
export type EmitsOptions = ObjectEmitsOptions | string [ ]
69
69
70
70
// Functional component
71
- export function mount <
72
- TestedComponent extends FunctionalComponent < Props > ,
73
- Props
74
- > (
75
- originalComponent : TestedComponent ,
71
+ // export function mount<
72
+ // TestedComponent extends FunctionalComponent<Props, E>,
73
+ // Props,
74
+ // E extends EmitsOptions = {}
75
+ // >(
76
+ // originalComponent: TestedComponent,
77
+ // options?: MountingOptions<Props>
78
+ // ): VueWrapper<ComponentPublicInstance<Props>>
79
+
80
+ // Functional component with emits
81
+ export function mount < Props , E extends EmitsOptions = { } > (
82
+ originalComponent : FunctionalComponent < Props , E > ,
76
83
options ?: MountingOptions < Props >
77
84
) : VueWrapper < ComponentPublicInstance < Props > >
78
85
Original file line number Diff line number Diff line change 1
1
import { expectError , expectType } from 'tsd'
2
- import { DefineComponent , defineComponent , reactive } from 'vue'
2
+ import {
3
+ DefineComponent ,
4
+ defineComponent ,
5
+ FunctionalComponent ,
6
+ reactive
7
+ } from 'vue'
3
8
import { mount } from '../src'
4
9
5
10
const AppWithDefine = defineComponent ( {
@@ -177,3 +182,24 @@ mount(ShimComponent, {
177
182
}
178
183
}
179
184
} )
185
+
186
+ // functional components
187
+ declare const FunctionalComponent : FunctionalComponent < {
188
+ bar : string
189
+ level : number
190
+ } >
191
+ declare const FunctionalComponentEmit : FunctionalComponent <
192
+ {
193
+ bar : string
194
+ level : number
195
+ } ,
196
+ { hello : ( foo : string , bar : string ) => void }
197
+ >
198
+
199
+ mount ( FunctionalComponent )
200
+ mount ( defineComponent ( FunctionalComponent ) )
201
+
202
+ mount ( FunctionalComponentEmit )
203
+
204
+ // @ts -ignore vue 3.0.2 doesn't work. FIX: https://github.com/vuejs/vue-next/pull/2494
205
+ mount ( defineComponent ( FunctionalComponentEmit ) )
Original file line number Diff line number Diff line change @@ -134,10 +134,10 @@ describe('emitted', () => {
134
134
} )
135
135
136
136
it ( 'gives a useful warning for functional components' , ( ) => {
137
- const Component : FunctionalComponent < { bar : string ; level : number } > = (
138
- props ,
139
- ctx
140
- ) => {
137
+ const Component : FunctionalComponent <
138
+ { bar : string ; level : number } ,
139
+ { hello : ( foo : string , bar : string ) => void }
140
+ > = ( props , ctx ) => {
141
141
return h ( `h${ props . level } ` , {
142
142
onClick : ( ) => ctx . emit ( 'hello' , 'foo' , props . bar )
143
143
} )
You can’t perform that action at this time.
0 commit comments