From 1b377d6af08916563f9dd3f26a175b09b86d37a3 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sun, 8 Dec 2024 22:41:47 +0800 Subject: [PATCH 1/4] fix(types): boolean casting of props on component instances --- packages/runtime-core/src/apiSetupHelpers.ts | 10 +++++----- packages/runtime-core/src/componentPublicInstance.ts | 7 ++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/runtime-core/src/apiSetupHelpers.ts b/packages/runtime-core/src/apiSetupHelpers.ts index 54712c6807a..19b89e2a3c3 100644 --- a/packages/runtime-core/src/apiSetupHelpers.ts +++ b/packages/runtime-core/src/apiSetupHelpers.ts @@ -81,10 +81,7 @@ export function defineProps< PP extends ComponentObjectPropsOptions = ComponentObjectPropsOptions, >(props: PP): Prettify>> // overload 3: typed-based declaration -export function defineProps(): DefineProps< - LooseRequired, - BooleanKey -> +export function defineProps(): DefineProps // implementation export function defineProps() { if (__DEV__) { @@ -93,7 +90,10 @@ export function defineProps() { return null as any } -export type DefineProps = Readonly & { +export type DefineProps< + T, + BKeys extends keyof T = BooleanKey +> = Readonly> & { readonly [K in BKeys]-?: boolean } diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index e9e7770ebd9..d1ca582cfd9 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -54,6 +54,7 @@ import { markAttrsAccessed } from './componentRenderUtils' import { currentRenderingInstance } from './componentRenderContext' import { warn } from './warning' import { installCompatInstanceProperties } from './compat/instance' +import type { DefineProps } from './apiSetupHelpers' import type { Directive } from './directives' /** @@ -333,7 +334,11 @@ export type ComponentPublicInstance< IfAny< P, P, - Readonly & Omit | keyof Defaults> + Readonly & + Omit< + DefineProps

, + keyof ShallowUnwrapRef | keyof Defaults + > > & ShallowUnwrapRef & UnwrapNestedRefs & From 895fd884b048c98a1d10a91f0e18af1ad7ff7af2 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 8 Dec 2024 14:44:44 +0000 Subject: [PATCH 2/4] [autofix.ci] apply automated fixes --- packages/runtime-core/src/apiSetupHelpers.ts | 7 +++---- packages/runtime-core/src/componentPublicInstance.ts | 5 +---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/runtime-core/src/apiSetupHelpers.ts b/packages/runtime-core/src/apiSetupHelpers.ts index 19b89e2a3c3..92c8a10235c 100644 --- a/packages/runtime-core/src/apiSetupHelpers.ts +++ b/packages/runtime-core/src/apiSetupHelpers.ts @@ -90,10 +90,9 @@ export function defineProps() { return null as any } -export type DefineProps< - T, - BKeys extends keyof T = BooleanKey -> = Readonly> & { +export type DefineProps> = Readonly< + LooseRequired +> & { readonly [K in BKeys]-?: boolean } diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index d1ca582cfd9..d0573113353 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -335,10 +335,7 @@ export type ComponentPublicInstance< P, P, Readonly & - Omit< - DefineProps

, - keyof ShallowUnwrapRef | keyof Defaults - > + Omit, keyof ShallowUnwrapRef | keyof Defaults> > & ShallowUnwrapRef & UnwrapNestedRefs & From d5d1461d282625929543109cdd4b8451fafdf8e6 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sun, 8 Dec 2024 23:08:21 +0800 Subject: [PATCH 3/4] fix: type --- packages/runtime-core/src/apiSetupHelpers.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/runtime-core/src/apiSetupHelpers.ts b/packages/runtime-core/src/apiSetupHelpers.ts index 92c8a10235c..d25d29aa79b 100644 --- a/packages/runtime-core/src/apiSetupHelpers.ts +++ b/packages/runtime-core/src/apiSetupHelpers.ts @@ -81,7 +81,7 @@ export function defineProps< PP extends ComponentObjectPropsOptions = ComponentObjectPropsOptions, >(props: PP): Prettify>> // overload 3: typed-based declaration -export function defineProps(): DefineProps +export function defineProps(): DefineProps> // implementation export function defineProps() { if (__DEV__) { @@ -90,11 +90,9 @@ export function defineProps() { return null as any } -export type DefineProps> = Readonly< - LooseRequired -> & { +export type DefineProps> = Readonly & { readonly [K in BKeys]-?: boolean -} +}; type BooleanKey = K extends any ? [T[K]] extends [boolean | undefined] From 18255786d3259c376940409602e1dcabb1090898 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 8 Dec 2024 15:09:14 +0000 Subject: [PATCH 4/4] [autofix.ci] apply automated fixes --- packages/runtime-core/src/apiSetupHelpers.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/src/apiSetupHelpers.ts b/packages/runtime-core/src/apiSetupHelpers.ts index d25d29aa79b..983960752cb 100644 --- a/packages/runtime-core/src/apiSetupHelpers.ts +++ b/packages/runtime-core/src/apiSetupHelpers.ts @@ -90,9 +90,12 @@ export function defineProps() { return null as any } -export type DefineProps> = Readonly & { +export type DefineProps< + T, + BKeys extends keyof T = BooleanKey, +> = Readonly & { readonly [K in BKeys]-?: boolean -}; +} type BooleanKey = K extends any ? [T[K]] extends [boolean | undefined]