diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 3c3159ce..b6df32a2 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -82,22 +82,27 @@ function toProxyRef( } as any } -type UnwrapArray = { [P in keyof T]: UnwrapRef } +// Super simple tuple checker +type Tupple> = T[0] extends T[1] + ? T[1] extends T[2] ? never : true + : true -type UnwrapProp = T extends ComputedRef - ? UnwrapRef - : T extends Ref - ? UnwrapRef - : T extends Function | CollectionTypes - ? T - : T extends object - ? UnwrapObject - : T extends Array ? Array> & UnwrapArray : T +export type UnwrapRef = T extends ComputedRef + ? UnwrapRefSimple + : T extends Ref ? UnwrapRefSimple : UnwrapRefSimple -type UnwrapObject = { [K in keyof T]: UnwrapProp } +type UnwrapRefSimple = T extends Function | CollectionTypes + ? T + : T extends Array + ? Tupple extends never ? UnwrappedArray : UnwrapTupple + : T extends object ? UnwrappedObject : T -export type UnwrapRef = T extends object - ? UnwrapObject - : T extends Function | CollectionTypes - ? T - : T extends Array ? Array> & UnwrapArray : T +export type UnwrapTupple = { [P in keyof T]: UnwrapRef } & { + length: number + [Symbol.iterator]: any + [Symbol.unscopables]: any +} + +interface UnwrappedArray extends Array> {} + +type UnwrappedObject = { [P in keyof T]: UnwrapRef }