types(runtime-core): improve PropType inference precision (#1863)
This commit is contained in:
@@ -40,14 +40,14 @@ export type ComponentObjectPropsOptions<P = Data> = {
|
||||
[K in keyof P]: Prop<P[K]> | null
|
||||
}
|
||||
|
||||
export type Prop<T> = PropOptions<T> | PropType<T>
|
||||
export type Prop<T, D = T> = PropOptions<T, D> | PropType<T>
|
||||
|
||||
type DefaultFactory<T> = () => T | null | undefined
|
||||
|
||||
interface PropOptions<T = any> {
|
||||
interface PropOptions<T = any, D = T> {
|
||||
type?: PropType<T> | true | null
|
||||
required?: boolean
|
||||
default?: T | DefaultFactory<T> | null | undefined
|
||||
default?: D | DefaultFactory<D> | null | undefined
|
||||
validator?(value: unknown): boolean
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ type InferPropType<T> = T extends null
|
||||
? Record<string, any>
|
||||
: T extends BooleanConstructor | { type: BooleanConstructor }
|
||||
? boolean
|
||||
: T extends Prop<infer V> ? V : T
|
||||
: T extends Prop<infer V, infer D> ? (unknown extends V ? D : V) : T
|
||||
|
||||
export type ExtractPropTypes<
|
||||
O,
|
||||
|
||||
Reference in New Issue
Block a user