From ab9add4f781e5c0f517afa4ad5d5331ac1f3af8f Mon Sep 17 00:00:00 2001 From: pikax Date: Wed, 8 Apr 2020 21:33:06 +0100 Subject: [PATCH] types: bring back my changes --- packages/reactivity/src/ref.ts | 37 ++++++++++++------- .../__tests__/apiTemplateRef.spec.ts | 1 - 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 3b334538..485f5646 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -103,16 +103,27 @@ function toProxyRef( // RelativePath extends object -> true type BaseTypes = string | number | boolean -// Recursively unwraps nested value bindings. -export type UnwrapRef = { - cRef: T extends ComputedRef ? UnwrapRef : T - ref: T extends Ref ? UnwrapRef : T - array: T - object: { [K in keyof T]: UnwrapRef } -}[T extends ComputedRef - ? 'cRef' - : T extends Array - ? 'array' - : T extends Ref | Function | CollectionTypes | BaseTypes - ? 'ref' // bail out on types that shouldn't be unwrapped - : T extends object ? 'object' : 'ref'] +// Super simple tuple checker +type Tupple> = T[0] extends T[1] + ? T[1] extends T[2] ? never : true + : true + +export type UnwrapRef = T extends ComputedRef + ? UnwrapRefSimple + : T extends Ref ? UnwrapRefSimple : UnwrapRefSimple + +type UnwrapRefSimple = T extends Function | CollectionTypes | BaseTypes | Ref + ? T + : T extends Array + ? Tupple extends never ? Array : UnwrapTupple + : T extends object ? UnwrappedObject : T + +export type UnwrapTupple = { [P in keyof T]: T[P] } & { + length: number + [Symbol.iterator]: any + [Symbol.unscopables]: any +} + +// interface UnwrappedArray extends Array {} + +type UnwrappedObject = { [P in keyof T]: UnwrapRef } diff --git a/packages/runtime-core/__tests__/apiTemplateRef.spec.ts b/packages/runtime-core/__tests__/apiTemplateRef.spec.ts index 1ba8526a..acf4f5b3 100644 --- a/packages/runtime-core/__tests__/apiTemplateRef.spec.ts +++ b/packages/runtime-core/__tests__/apiTemplateRef.spec.ts @@ -4,7 +4,6 @@ import { h, render, nextTick, - Ref, defineComponent, reactive } from '@vue/runtime-test'