diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 3b334538c..485f56462 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 1ba8526aa..acf4f5b37 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'