types: fix ref unwrapping when nested inside arrays (#331)

This commit is contained in:
扩散性百万甜面包
2019-10-19 02:54:05 +08:00
committed by Evan You
parent 58fcd15000
commit 3cd2f7e68e
2 changed files with 21 additions and 3 deletions

View File

@@ -80,6 +80,25 @@ describe('reactivity/ref', () => {
expect(typeof (c.value.b + 1)).toBe('number')
})
it('should properly unwrap ref types nested inside arrays', () => {
const arr = ref([1, ref(1)]).value
// should unwrap to number[]
arr[0]++
arr[1]++
const arr2 = ref([1, new Map<string, any>(), ref('1')]).value
const value = arr2[0]
if (typeof value === 'string') {
value + 'foo'
} else if (typeof value === 'number') {
value + 1
} else {
// should narrow down to Map type
// and not contain any Ref type
value.has('foo')
}
})
test('isRef', () => {
expect(isRef(ref(1))).toBe(true)
expect(isRef(computed(() => 1))).toBe(true)