From 173add4fbc14b7aa71c8e27d5dff673018d0b176 Mon Sep 17 00:00:00 2001 From: Carlos Rodrigues Date: Mon, 13 Nov 2023 08:26:36 +0000 Subject: [PATCH] fix preparing for vue 3.3.8 --- src/mount.ts | 19 +++++++++++-------- test-dts/mount.d-test.ts | 18 ++++++++++-------- test-dts/shallowMount.d-test.ts | 4 ++-- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/mount.ts b/src/mount.ts index f43833a04..d0883b504 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -18,10 +18,10 @@ type WithArray = T | T[] type ComponentData = T extends { data?(...args: any): infer D } ? D : {} -export type ComponentMountingOptions = Omit< - MountingOptions, ComponentData>, - 'slots' -> & { +export type ComponentMountingOptions< + T, + P extends ComponentProps = ComponentProps +> = Omit>, 'slots'> & { slots?: { [K in keyof ComponentSlots]: WithArray< | ShimSlotReturnType[K]> @@ -43,17 +43,20 @@ export function mount< ? { [key in PropNames extends string ? PropNames : string]?: any } : Props > - : DefineComponent + : DefineComponent, + P extends ComponentProps = ComponentProps >( originalComponent: T, - options?: ComponentMountingOptions + options?: ComponentMountingOptions ): VueWrapper< ComponentProps & ComponentData & ComponentExposed, ComponentPublicInstance< ComponentProps, - ComponentData & ComponentExposed + ComponentData & ComponentExposed & Omit> > -> +> & { + LOOL: Exclude> +} // implementation export function mount( diff --git a/test-dts/mount.d-test.ts b/test-dts/mount.d-test.ts index 446d4075f..c7955bdb5 100644 --- a/test-dts/mount.d-test.ts +++ b/test-dts/mount.d-test.ts @@ -66,7 +66,7 @@ const AppWithProps = { props: { a: { type: String, - required: true + required: true as true } }, template: '' @@ -91,7 +91,7 @@ expectError( ) const AppWithArrayProps = { - props: ['a'], + props: ['a'] as ['a'], template: '' } @@ -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( - mount((props: { a: number }, ctx: any) => { }, { + mount((props: { a: number }, ctx: any) => {}, { props: { a: 22 } @@ -247,7 +247,7 @@ class CustomClassComponent { return this.props } context: SetupContext - render(): VNodeChild { } + render(): VNodeChild {} } class NoPropCustomClassComponent extends CustomClassComponent { count = ref(0) @@ -281,7 +281,8 @@ class WithPropCustomClassComponent extends CustomClassComponent { $props: CustomClassComponentProps }), + WithPropCustomClassComponent as typeof WithPropCustomClassComponent & + (new () => { $props: CustomClassComponentProps }), { // @ts-expect-error should has props error props: {} @@ -289,7 +290,8 @@ expectError( ) ) mount( - WithPropCustomClassComponent as typeof WithPropCustomClassComponent & (new () => { $props: CustomClassComponentProps }), + WithPropCustomClassComponent as typeof WithPropCustomClassComponent & + (new () => { $props: CustomClassComponentProps }), { props: { size: 'small' } } diff --git a/test-dts/shallowMount.d-test.ts b/test-dts/shallowMount.d-test.ts index 044aa058c..b25cd144d 100644 --- a/test-dts/shallowMount.d-test.ts +++ b/test-dts/shallowMount.d-test.ts @@ -38,7 +38,7 @@ const AppWithProps = { props: { a: { type: String, - required: true + required: true as true } }, template: '' @@ -65,7 +65,7 @@ expectError( ) const AppWithArrayProps = { - props: ['a'], + props: ['a'] as ['a'], template: '' }