fix(types): correct type inference of all-optional props (#11644)

fix #11733
fix vuejs/language-tools#4704
This commit is contained in:
山吹色御守 2024-09-20 20:36:57 +08:00 committed by GitHub
parent 235ea4772e
commit 9eca65ee98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 6 deletions

View File

@ -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,

View File

@ -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