chore: simplifying and improve tupple & array output type on ref
This commit is contained in:
parent
14f1814292
commit
07ff08956f
@ -82,22 +82,27 @@ function toProxyRef<T extends object, K extends keyof T>(
|
|||||||
} as any
|
} as any
|
||||||
}
|
}
|
||||||
|
|
||||||
type UnwrapArray<T> = { [P in keyof T]: UnwrapRef<T[P]> }
|
// Super simple tuple checker
|
||||||
|
type Tupple<T extends Array<any>> = T[0] extends T[1]
|
||||||
|
? T[1] extends T[2] ? never : true
|
||||||
|
: true
|
||||||
|
|
||||||
type UnwrapProp<T> = T extends ComputedRef<infer V>
|
export type UnwrapRef<T> = T extends ComputedRef<infer V>
|
||||||
? UnwrapRef<V>
|
? UnwrapRefSimple<V>
|
||||||
: T extends Ref<infer V>
|
: T extends Ref<infer V> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>
|
||||||
? UnwrapRef<V>
|
|
||||||
: T extends Function | CollectionTypes
|
type UnwrapRefSimple<T> = T extends Function | CollectionTypes
|
||||||
? T
|
? T
|
||||||
: T extends object
|
: T extends Array<infer V>
|
||||||
? UnwrapObject<T>
|
? Tupple<T> extends never ? UnwrappedArray<V> : UnwrapTupple<T>
|
||||||
: T extends Array<infer V> ? Array<UnwrapRef<V>> & UnwrapArray<T> : T
|
: T extends object ? UnwrappedObject<T> : T
|
||||||
|
|
||||||
type UnwrapObject<T> = { [K in keyof T]: UnwrapProp<T[K]> }
|
export type UnwrapTupple<T> = { [P in keyof T]: UnwrapRef<T[P]> } & {
|
||||||
|
length: number
|
||||||
|
[Symbol.iterator]: any
|
||||||
|
[Symbol.unscopables]: any
|
||||||
|
}
|
||||||
|
|
||||||
export type UnwrapRef<T> = T extends object
|
interface UnwrappedArray<T> extends Array<UnwrapRef<T>> {}
|
||||||
? UnwrapObject<T>
|
|
||||||
: T extends Function | CollectionTypes
|
type UnwrappedObject<T> = { [P in keyof T]: UnwrapRef<T[P]> }
|
||||||
? T
|
|
||||||
: T extends Array<infer V> ? Array<UnwrapRef<V>> & UnwrapArray<T> : T
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user