Skip to content

Commit c7242ef

Browse files
committed
updated
1 parent 7368563 commit c7242ef

File tree

7 files changed

+272
-88
lines changed

7 files changed

+272
-88
lines changed

patches/@[email protected]

Lines changed: 109 additions & 42 deletions
Large diffs are not rendered by default.

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/baseWrapper.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { textContent } from './utils'
22
import type { TriggerOptions } from './createDomEvent'
33
import {
4-
ComponentDefineOptions,
4+
DefineComponentOptions,
5+
DefineComponentFromOptions,
56
ComponentInjectOptions,
67
ComponentInstance,
78
ComponentInternalInstance,
@@ -131,7 +132,7 @@ export default abstract class BaseWrapper<ElementType extends Node>
131132
S extends SlotsType = {},
132133
Options = {}
133134
>(
134-
selector: ComponentDefineOptions<
135+
selector: DefineComponentOptions<
135136
Props,
136137
RawBindings,
137138
D,
@@ -149,7 +150,7 @@ export default abstract class BaseWrapper<ElementType extends Node>
149150
): VueWrapper<
150151
Props extends DefinedComponent
151152
? ComponentInstance<Props>
152-
: CreateComponentPublicInstance<
153+
: DefineComponentFromOptions<
153154
Props,
154155
RawBindings,
155156
D,
@@ -158,10 +159,9 @@ export default abstract class BaseWrapper<ElementType extends Node>
158159
Mixin,
159160
Extends,
160161
E,
161-
Props,
162-
{},
163-
true,
162+
EE,
164163
I,
164+
II,
165165
S,
166166
Options
167167
>

src/mount.ts

Lines changed: 108 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ import {
33
DefineComponent,
44
VNode,
55
ComponentInstance,
6-
ComputedOptions,
7-
MethodOptions,
8-
ComponentOptionsMixin,
96
EmitsOptions,
10-
ComponentInjectOptions,
11-
SlotsType,
12-
ComponentDefineOptions
7+
ComponentObjectPropsOptions,
8+
ExtractPropTypes
139
} from 'vue'
1410
import type { ComponentSlots } from 'vue-component-type-helpers'
1511
import { createInstance } from './createInstance'
@@ -108,24 +104,117 @@ export type ComponentMountingOptions<T, P> = Omit<
108104
// >
109105
// ): { props: Props }
110106
// defineComponent
107+
108+
// TODO import from vue
109+
export type ResolveProps<Props, E extends EmitsOptions> = Readonly<
110+
([Props] extends [string]
111+
? { [key in Props]?: any }
112+
: [Props] extends [ComponentObjectPropsOptions]
113+
? ExtractPropTypes<Props>
114+
: Props extends never[]
115+
? {}
116+
: Props) &
117+
({} extends E ? {} : {})
118+
>
119+
120+
// export function mount<Component>(
121+
// component: Component &
122+
// DefineComponent<
123+
// any,
124+
// any,
125+
// any,
126+
// any,
127+
// any,
128+
// any,
129+
// any,
130+
// any,
131+
// any,
132+
// any,
133+
// any,
134+
// any,
135+
// any
136+
// >,
137+
// options?: ComponentMountingOptions<
138+
// Component,
139+
// ComponentPropsWithDefaultOptional<Component>
140+
// >
141+
// ): VueWrapper<ComponentInstance<Component>> & {
142+
// LOL: Component
143+
// LOOL: ComponentPropsWithDefaultOptional<Component>
144+
// }
145+
111146
export function mount<
112-
T extends DefineComponent<
113-
PropsOrOptions,
114-
any,
115-
any,
116-
any,
117-
any,
118-
any,
119-
any,
120-
any,
121-
any,
122-
any
123-
>,
124-
PropsOrOptions extends object
147+
T extends DefineComponent<any, any, any, any, any, any, any, any, any, any>
125148
>(
126149
originalComponent: T,
127150
options?: ComponentMountingOptions<T, ComponentPropsWithDefaultOptional<T>>
128151
): VueWrapper<ComponentInstance<T>>
152+
153+
// export function mount<
154+
// Props = {},
155+
// RawBindings = {},
156+
// D = {},
157+
// C extends ComputedOptions = {},
158+
// M extends MethodOptions = {},
159+
// Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
160+
// Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
161+
// E extends EmitsOptions = {},
162+
// EE extends string = string,
163+
// I extends ComponentInjectOptions = {},
164+
// II extends string = string,
165+
// S extends SlotsType = {},
166+
// Options = {},
167+
// Component extends DefineComponentOptions<
168+
// Props,
169+
// RawBindings,
170+
// D,
171+
// C,
172+
// M,
173+
// Mixin,
174+
// Extends,
175+
// E,
176+
// EE,
177+
// I,
178+
// II,
179+
// S,
180+
// Options
181+
// > = DefineComponentOptions<
182+
// Props,
183+
// RawBindings,
184+
// D,
185+
// C,
186+
// M,
187+
// Mixin,
188+
// Extends,
189+
// E,
190+
// EE,
191+
// I,
192+
// II,
193+
// S,
194+
// Options
195+
// >
196+
// >(
197+
// componentOptions: DefineComponentOptions<
198+
// Props,
199+
// RawBindings,
200+
// D,
201+
// C,
202+
// M,
203+
// Mixin,
204+
// Extends,
205+
// E,
206+
// EE,
207+
// I,
208+
// II,
209+
// S,
210+
// Options
211+
// >,
212+
// options?: ComponentMountingOptions<
213+
// Component,
214+
// ComponentPropsWithDefaultOptional<Component>
215+
// >
216+
// ): VueWrapper<ComponentInstance<Props>>
217+
129218
// implementation
130219
export function mount(
131220
inputComponent: any,

test-dts/mount.d-test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ mount(AppWithProps, {
8585

8686
expectError(
8787
mount(AppWithProps, {
88-
// @ts-expect-error wrong prop type should not compile
88+
// @ts-expect-error wrong prop type should not compile
8989
props: { a: 2 }
9090
})
9191
)
9292

9393
const AppWithArrayProps = {
94-
props: ['a'],
94+
props: ['a'] as ['a'],
9595
template: ''
96-
} as const
96+
}
9797

9898
// accept props - vm is properly typed
9999
expectType<string>(

test-dts/shallowMount.d-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ expectError(
6565
)
6666

6767
const AppWithArrayProps = {
68-
props: ['a'],
68+
props: ['a'] as ['a'],
6969
template: ''
70-
} as const
70+
}
7171

7272
// accept props
7373
// vm is properly typed

test-dts/wrapper.d-test.ts

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,48 @@ expectType<number | undefined>(propsWrapper.props('bar'))
146146
// @ts-expect-error :: unknown prop
147147
propsWrapper.props('badProp')
148148

149-
const requiredPropsWrapper = mount(
150-
defineComponent({
151-
props: {
152-
foo: { type: String, required: true },
153-
bar: { type: Number, required: true }
154-
}
155-
}),
156-
{
157-
props: {
158-
foo: 'abc',
159-
bar: 123
160-
}
149+
// const cc = defineComponent({
150+
// props: {
151+
// foo: { type: String, required: true },
152+
// bar: { type: Number, required: true }
153+
// }
154+
// })
155+
// mount(
156+
// defineComponent({
157+
// props: {
158+
// foo: { type: String, required: true },
159+
// bar: { type: Number, required: true }
160+
// }
161+
// }),
162+
// {
163+
// props: {
164+
// foo: 'aaa',
165+
// bar: 123
166+
// }
167+
// }
168+
// )
169+
170+
// mount({
171+
// props: {
172+
// a: String
173+
// },
174+
// setup(props) {
175+
// props
176+
// }
177+
// })
178+
179+
const c = defineComponent({
180+
props: {
181+
foo: { type: String, required: true },
182+
bar: { type: Number, required: true }
161183
}
162-
)
184+
})
185+
const requiredPropsWrapper = mount(c, {
186+
props: {
187+
foo: 'abc',
188+
bar: 123
189+
}
190+
})
163191

164192
requiredPropsWrapper.setProps({
165193
foo: 'abc'

0 commit comments

Comments
 (0)