Skip to content

Commit

Permalink
fix(types): improve defineProps return type with generic arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 5, 2023
1 parent b2c874e commit 91a931a
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/runtime-core/src/apiSetupHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function defineProps<
PP extends ComponentObjectPropsOptions = ComponentObjectPropsOptions
>(props: PP): Prettify<Readonly<ExtractPropTypes<PP>>>
// overload 3: typed-based declaration
export function defineProps<TypeProps>(): ResolveProps<TypeProps>
export function defineProps<TypeProps>(): DefineProps<TypeProps>
// implementation
export function defineProps() {
if (__DEV__) {
Expand All @@ -85,13 +85,9 @@ export function defineProps() {
return null as any
}

type ResolveProps<T, BooleanKeys extends keyof T = BooleanKey<T>> = Prettify<
Readonly<
T & {
[K in BooleanKeys]-?: boolean
}
>
>
type DefineProps<T> = Readonly<T> & {
readonly [K in BooleanKey<T>]-?: boolean
}

type BooleanKey<T, K extends keyof T = keyof T> = K extends any
? [T[K]] extends [boolean | undefined]
Expand Down

0 comments on commit 91a931a

Please sign in to comment.