Skip to content

Commit 48b1293

Browse files
committed
fix: support for DefineComponent shim
1 parent dd780f8 commit 48b1293

File tree

3 files changed

+84
-8
lines changed

3 files changed

+84
-8
lines changed

src/mount.ts

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ import {
1717
ComponentPropsOptions,
1818
AppConfig,
1919
VNodeProps,
20-
ComponentOptionsMixin
20+
ComponentOptionsMixin,
21+
DefineComponent,
22+
MethodOptions,
23+
AllowedComponentProps,
24+
ComponentCustomProps,
25+
ExtractDefaultPropTypes
2126
} from 'vue'
2227

2328
import { config } from './config'
@@ -34,6 +39,8 @@ import {
3439
} from './constants'
3540
import { stubComponents } from './stubs'
3641

42+
type PublicProps = VNodeProps & AllowedComponentProps & ComponentCustomProps
43+
3744
type Slot = VNode | string | { render: Function } | Function | Component
3845

3946
type SlotDictionary = {
@@ -46,6 +53,7 @@ interface MountingOptions<Props, Data = {}> {
4653
: Data extends object
4754
? Partial<Data>
4855
: never
56+
// data?: {} extends Data ? never : () => Partial<Data>
4957
props?: Props
5058
/** @deprecated */
5159
propsData?: Props
@@ -78,10 +86,60 @@ export function mount<
7886
): VueWrapper<ComponentPublicInstance<Props>>
7987

8088
// Component declared with defineComponent
81-
export function mount<TestedComponent extends ComponentPublicInstance>(
82-
originalComponent: { new (): TestedComponent } & Component,
83-
options?: MountingOptions<TestedComponent['$props'], TestedComponent['$data']>
84-
): VueWrapper<TestedComponent>
89+
// export function mount<TestedComponent extends ComponentPublicInstance>(
90+
// originalComponent: { new (): TestedComponent } & Component,
91+
// options?: MountingOptions<TestedComponent['$props'], TestedComponent['$data']>
92+
// ): VueWrapper<TestedComponent>
93+
94+
export function mount<
95+
PropsOrPropOptions = {},
96+
RawBindings = {},
97+
D = {},
98+
C extends ComputedOptions = ComputedOptions,
99+
M extends MethodOptions = MethodOptions,
100+
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
101+
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
102+
E extends EmitsOptions = Record<string, any>,
103+
EE extends string = string,
104+
PP = PublicProps,
105+
Props = Readonly<ExtractPropTypes<PropsOrPropOptions>>,
106+
Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>
107+
>(
108+
component: DefineComponent<
109+
PropsOrPropOptions,
110+
RawBindings,
111+
D,
112+
C,
113+
M,
114+
Mixin,
115+
Extends,
116+
E,
117+
EE,
118+
PP,
119+
Props,
120+
Defaults
121+
>,
122+
options?: MountingOptions<Props, D>
123+
): VueWrapper<
124+
InstanceType<
125+
DefineComponent<
126+
PropsOrPropOptions,
127+
RawBindings,
128+
D,
129+
C,
130+
M,
131+
Mixin,
132+
Extends,
133+
E,
134+
EE,
135+
PP,
136+
Props,
137+
Defaults
138+
>
139+
>
140+
>
141+
142+
//Props //VueWrapper<InstanceType<C>> //ExtractPropTypes<PropsOrOptions> //PropsOrOptions //VueWrapper<ThisType<C>>
85143

86144
// Component declared with no props
87145
export function mount<

src/vueShims.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
declare module '*.vue' {
22
// TODO: Figure out the typing for this
3-
import Vue from 'vue'
4-
export default any
3+
import type { DefineComponent } from 'vue'
4+
const component: DefineComponent
5+
export default component
56
}

test-dts/mount.d-test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expectError, expectType } from 'tsd'
2-
import { defineComponent } from 'vue'
2+
import { DefineComponent, defineComponent } from 'vue'
33
import { mount } from '../src'
44

55
const AppWithDefine = defineComponent({
@@ -160,3 +160,20 @@ mount(AppWithProps, {
160160
}
161161
}
162162
})
163+
164+
declare const ShimComponent: DefineComponent
165+
166+
mount(ShimComponent, {
167+
props: {
168+
msg: 1
169+
}
170+
})
171+
172+
// TODO it should work
173+
// mount(ShimedComponent, {
174+
// data() {
175+
// return {
176+
// a: 1
177+
// }
178+
// }
179+
// })

0 commit comments

Comments
 (0)