diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 569e4e0d..d2898673 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -128,31 +128,13 @@ export function toRef( // RelativePath extends object -> true type BaseTypes = string | number | boolean | Node | Window -// Super simple tuple checker -type IsTuple> = 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 - | Element +type UnwrapRefSimple = T extends Function | CollectionTypes | BaseTypes | Ref ? T - : T extends Array - ? IsTuple extends true ? UnwrapTuple : Array - : T extends object ? UnwrappedObject : T - -export type UnwrapTuple = { [P in keyof T]: T[P] } & { - length: number - [Symbol.iterator]: any - [Symbol.unscopables]: any -} + : T extends Array ? T : T extends object ? UnwrappedObject : T // Extract all known symbols from an object // when unwrapping Object the symbols are not `in keyof`, this should cover all the diff --git a/test-dts/ref.test-d.ts b/test-dts/ref.test-d.ts index a2c71748..f9b72312 100644 --- a/test-dts/ref.test-d.ts +++ b/test-dts/ref.test-d.ts @@ -21,14 +21,15 @@ function plainType(arg: number | Ref) { expectType>(nestedRef) expectType<{ foo: number }>(nestedRef.value) + // tuple + expectType<[number, string]>(unref(ref([1, '1']))) + interface IteratorFoo { [Symbol.iterator]: any } - expectType> | Ref>( - ref(null) - ) - expectType | Ref>(ref(null)) + // with symbol + expectType(unref(ref(null))) } plainType(1)