Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preparing for Vue 3.3.9 #2240

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ type WithArray<T> = T | T[]

type ComponentData<T> = T extends { data?(...args: any): infer D } ? D : {}

export type ComponentMountingOptions<T> = Omit<
MountingOptions<ComponentProps<T>, ComponentData<T>>,
'slots'
> & {
export type ComponentMountingOptions<
T,
P extends ComponentProps<T> = ComponentProps<T>
> = Omit<MountingOptions<P, ComponentData<T>>, 'slots'> & {
slots?: {
[K in keyof ComponentSlots<T>]: WithArray<
| ShimSlotReturnType<ComponentSlots<T>[K]>
Expand All @@ -43,17 +43,20 @@ export function mount<
? { [key in PropNames extends string ? PropNames : string]?: any }
: Props
>
: DefineComponent
: DefineComponent,
P extends ComponentProps<C> = ComponentProps<C>
>(
originalComponent: T,
options?: ComponentMountingOptions<C>
options?: ComponentMountingOptions<C, P>
): VueWrapper<
ComponentProps<C> & ComponentData<C> & ComponentExposed<C>,
ComponentPublicInstance<
ComponentProps<C>,
ComponentData<C> & ComponentExposed<C>
ComponentData<C> & ComponentExposed<C> & Omit<P, keyof ComponentProps<C>>
>
>
> & {
LOOL: Exclude<P, ComponentProps<C>>
}

// implementation
export function mount(
Expand Down
18 changes: 10 additions & 8 deletions test-dts/mount.d-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const AppWithProps = {
props: {
a: {
type: String,
required: true
required: true as true
}
},
template: ''
Expand All @@ -91,7 +91,7 @@ expectError(
)

const AppWithArrayProps = {
props: ['a'],
props: ['a'] as ['a'],
template: ''
}

Expand Down Expand Up @@ -134,16 +134,16 @@ mount(AppWithoutProps, {
// Functional tests

expectError(
mount((props: { a: 1 }) => { }, {
mount((props: { a: 1 }) => {}, {
props: {
// @ts-expect-error wrong props
a: '222'
a: '222'
}
})
)

expectType<number>(
mount((props: { a: number }, ctx: any) => { }, {
mount((props: { a: number }, ctx: any) => {}, {
props: {
a: 22
}
Expand Down Expand Up @@ -247,7 +247,7 @@ class CustomClassComponent<Props extends {} = {}> {
return this.props
}
context: SetupContext
render(): VNodeChild { }
render(): VNodeChild {}
}
class NoPropCustomClassComponent extends CustomClassComponent {
count = ref(0)
Expand Down Expand Up @@ -281,15 +281,17 @@ class WithPropCustomClassComponent extends CustomClassComponent<CustomClassCompo

expectError(
mount(
WithPropCustomClassComponent as typeof WithPropCustomClassComponent & (new () => { $props: CustomClassComponentProps }),
WithPropCustomClassComponent as typeof WithPropCustomClassComponent &
(new () => { $props: CustomClassComponentProps }),
{
// @ts-expect-error should has props error
props: {}
}
)
)
mount(
WithPropCustomClassComponent as typeof WithPropCustomClassComponent & (new () => { $props: CustomClassComponentProps }),
WithPropCustomClassComponent as typeof WithPropCustomClassComponent &
(new () => { $props: CustomClassComponentProps }),
{
props: { size: 'small' }
}
Expand Down
4 changes: 2 additions & 2 deletions test-dts/shallowMount.d-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const AppWithProps = {
props: {
a: {
type: String,
required: true
required: true as true
}
},
template: ''
Expand All @@ -65,7 +65,7 @@ expectError(
)

const AppWithArrayProps = {
props: ['a'],
props: ['a'] as ['a'],
template: ''
}

Expand Down