wip: improve ref typing
This commit is contained in:
parent
caba6d5c9e
commit
96d65e1ab5
@ -61,4 +61,14 @@ describe('observer/value', () => {
|
||||
expect(dummy2).toBe(3)
|
||||
expect(dummy3).toBe(3)
|
||||
})
|
||||
|
||||
it('should unwrap nested values in types', () => {
|
||||
const a = {
|
||||
b: ref(0)
|
||||
}
|
||||
|
||||
const c = ref(a)
|
||||
|
||||
expect(typeof (c.value.b + 1)).toBe('number')
|
||||
})
|
||||
})
|
||||
|
@ -6,7 +6,7 @@ import { reactive } from './reactive'
|
||||
export const knownValues = new WeakSet()
|
||||
|
||||
export interface Ref<T> {
|
||||
value: T
|
||||
value: T extends Ref<infer V> ? Ref<V> : UnwrapRef<T>
|
||||
}
|
||||
|
||||
const convert = (val: any): any => (isObject(val) ? reactive(val) : val)
|
||||
@ -24,7 +24,7 @@ export function ref<T>(raw: T): Ref<T> {
|
||||
}
|
||||
}
|
||||
knownValues.add(v)
|
||||
return v
|
||||
return v as any
|
||||
}
|
||||
|
||||
export function isRef(v: any): v is Ref<any> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user