From 07ff08956ffc45eeba6a4df071b448c585b5ad6d Mon Sep 17 00:00:00 2001 From: pikax Date: Sat, 4 Jan 2020 14:09:52 +0000 Subject: [PATCH] chore: simplifying and improve tupple & array output type on ref --- packages/reactivity/src/ref.ts | 37 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) 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 }