From 14f1814292c8586802e4d1c6484a115e4000ce0f Mon Sep 17 00:00:00 2001 From: pikax Date: Sat, 4 Jan 2020 10:10:30 +0000 Subject: [PATCH] types: improve type error logging and nest ref types --- packages/reactivity/src/ref.ts | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index e2ff79e1..3c3159ce 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -84,18 +84,20 @@ function toProxyRef( type UnwrapArray = { [P in keyof T]: UnwrapRef } -// Recursively unwraps nested value bindings. -export type UnwrapRef = { - cRef: T extends ComputedRef ? UnwrapRef : T - ref: T extends Ref ? UnwrapRef : T - array: T extends Array ? Array> & UnwrapArray : T - object: { [K in keyof T]: UnwrapRef } -}[T extends ComputedRef - ? 'cRef' - : T extends Ref - ? 'ref' - : T extends Array - ? 'array' - : T extends Function | CollectionTypes - ? 'ref' // bail out on types that shouldn't be unwrapped - : T extends object ? 'object' : 'ref'] +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 + +type UnwrapObject = { [K in keyof T]: UnwrapProp } + +export type UnwrapRef = T extends object + ? UnwrapObject + : T extends Function | CollectionTypes + ? T + : T extends Array ? Array> & UnwrapArray : T