types(ref): improve UnwrapRef types (#266)
This commit is contained in:
parent
d2bcedb213
commit
d8b2b9eb9c
@ -7,7 +7,7 @@ export interface ComputedRef<T> extends WritableComputedRef<T> {
|
||||
}
|
||||
|
||||
export interface WritableComputedRef<T> extends Ref<T> {
|
||||
readonly effect: ReactiveEffect
|
||||
readonly effect: ReactiveEffect<T>
|
||||
}
|
||||
|
||||
export interface WritableComputedOptions<T> {
|
||||
|
@ -2,6 +2,7 @@ import { track, trigger } from './effect'
|
||||
import { OperationTypes } from './operations'
|
||||
import { isObject } from '@vue/shared'
|
||||
import { reactive } from './reactive'
|
||||
import { ComputedRef, WritableComputedRef } from './computed'
|
||||
|
||||
export const refSymbol = Symbol(__DEV__ ? 'refSymbol' : '')
|
||||
|
||||
@ -71,11 +72,17 @@ type BailTypes =
|
||||
|
||||
// Recursively unwraps nested value bindings.
|
||||
export type UnwrapRef<T> = {
|
||||
cRef: T extends ComputedRef<infer V> ? UnwrapRef<V> : T
|
||||
wcRef: T extends WritableComputedRef<infer V> ? UnwrapRef<V> : T
|
||||
ref: T extends Ref<infer V> ? UnwrapRef<V> : T
|
||||
array: T extends Array<infer V> ? Array<UnwrapRef<V>> : T
|
||||
object: { [K in keyof T]: UnwrapRef<T[K]> }
|
||||
stop: T
|
||||
}[T extends Ref
|
||||
}[T extends ComputedRef<any>
|
||||
? 'cRef'
|
||||
: T extends WritableComputedRef<any>
|
||||
? 'wcRef'
|
||||
: T extends Ref
|
||||
? 'ref'
|
||||
: T extends Array<any>
|
||||
? 'array'
|
||||
|
Loading…
Reference in New Issue
Block a user