Skip to content

Commit

Permalink
fix(types): correct type inference of all-optional props (#11644)
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX authored Sep 20, 2024
1 parent 235ea47 commit 9eca65e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 7 additions & 5 deletions packages/runtime-core/src/apiDefineComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,13 @@ export function defineComponent<
? TypeEmitsToOptions<TypeEmits>
: RuntimeEmitsOptions,
InferredProps = unknown extends TypeProps
? string extends RuntimePropsKeys
? ComponentObjectPropsOptions extends RuntimePropsOptions
? {}
: ExtractPropTypes<RuntimePropsOptions>
: { [key in RuntimePropsKeys]?: any }
? keyof TypeProps extends never
? string extends RuntimePropsKeys
? ComponentObjectPropsOptions extends RuntimePropsOptions
? {}
: ExtractPropTypes<RuntimePropsOptions>
: { [key in RuntimePropsKeys]?: any }
: TypeProps
: TypeProps,
TypeRefs extends Record<string, unknown> = {},
TypeEl extends Element = any,
Expand Down
4 changes: 3 additions & 1 deletion packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ type InferPropType<T, NullAsAny = true> = [T] extends [null]
: InferPropType<U, false>
: [T] extends [Prop<infer V, infer D>]
? unknown extends V
? IfAny<V, V, D>
? keyof V extends never
? IfAny<V, V, D>
: V
: V
: T

Expand Down

0 comments on commit 9eca65e

Please sign in to comment.