Skip to content

Commit c2ff6f5

Browse files
authored
Merge pull request #73 from cexbrayat/fix/vm-types
fix: improve vm types
2 parents c8d13cf + be92e32 commit c2ff6f5

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/mount.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,18 @@ interface MountingOptions {
4141
stubs?: Record<string, any>
4242
}
4343

44-
export function mount<T extends any>(
45-
originalComponent: any,
44+
export function mount<TestedComponent extends ComponentPublicInstance>(
45+
originalComponent: new () => TestedComponent,
46+
options?: MountingOptions
47+
): VueWrapper<TestedComponent>
48+
export function mount(
49+
originalComponent: Component,
4650
options?: MountingOptions
4751
): VueWrapper<any>
48-
export function mount<T extends ComponentPublicInstance>(
49-
originalComponent: new () => T,
52+
export function mount(
53+
originalComponent: any,
5054
options?: MountingOptions
51-
): VueWrapper<T> {
55+
): VueWrapper<any> {
5256
const component = { ...originalComponent }
5357

5458
// Reset the document.body
@@ -158,5 +162,5 @@ export function mount<T extends ComponentPublicInstance>(
158162
// mount the app!
159163
const app = vm.mount(el)
160164

161-
return createWrapper<T>(app, events, setProps)
165+
return createWrapper(app, events, setProps)
162166
}

test-dts/index.d-test.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,15 @@ const App = defineComponent({
99
template: ''
1010
})
1111

12-
const wrapper = mount(App)
13-
expectType<any>(wrapper.vm.a) // should be string
12+
let wrapper = mount(App)
13+
expectType<string>(wrapper.vm.a)
14+
15+
const AppWithoutDefine = {
16+
props: {
17+
a: String
18+
},
19+
template: ''
20+
}
21+
22+
wrapper = mount(AppWithoutDefine)
23+
expectType<string>(wrapper.vm.a)

0 commit comments

Comments
 (0)