Skip to content

Commit ab9add4

Browse files
committed
types: bring back my changes
1 parent 5ae7414 commit ab9add4

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

packages/reactivity/src/ref.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,27 @@ function toProxyRef<T extends object, K extends keyof T>(
103103
// RelativePath extends object -> true
104104
type BaseTypes = string | number | boolean
105105

106-
// Recursively unwraps nested value bindings.
107-
export type UnwrapRef<T> = {
108-
cRef: T extends ComputedRef<infer V> ? UnwrapRef<V> : T
109-
ref: T extends Ref<infer V> ? UnwrapRef<V> : T
110-
array: T
111-
object: { [K in keyof T]: UnwrapRef<T[K]> }
112-
}[T extends ComputedRef<any>
113-
? 'cRef'
114-
: T extends Array<any>
115-
? 'array'
116-
: T extends Ref | Function | CollectionTypes | BaseTypes
117-
? 'ref' // bail out on types that shouldn't be unwrapped
118-
: T extends object ? 'object' : 'ref']
106+
// Super simple tuple checker
107+
type Tupple<T extends Array<any>> = T[0] extends T[1]
108+
? T[1] extends T[2] ? never : true
109+
: true
110+
111+
export type UnwrapRef<T> = T extends ComputedRef<infer V>
112+
? UnwrapRefSimple<V>
113+
: T extends Ref<infer V> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>
114+
115+
type UnwrapRefSimple<T> = T extends Function | CollectionTypes | BaseTypes | Ref
116+
? T
117+
: T extends Array<infer V>
118+
? Tupple<T> extends never ? Array<V> : UnwrapTupple<T>
119+
: T extends object ? UnwrappedObject<T> : T
120+
121+
export type UnwrapTupple<T> = { [P in keyof T]: T[P] } & {
122+
length: number
123+
[Symbol.iterator]: any
124+
[Symbol.unscopables]: any
125+
}
126+
127+
// interface UnwrappedArray<T> extends Array<T> {}
128+
129+
type UnwrappedObject<T> = { [P in keyof T]: UnwrapRef<T[P]> }

packages/runtime-core/__tests__/apiTemplateRef.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
h,
55
render,
66
nextTick,
7-
Ref,
87
defineComponent,
98
reactive
109
} from '@vue/runtime-test'

0 commit comments

Comments
 (0)