fix(types): ref value type unwrapping should happen at creation time

This commit is contained in:
Evan You
2020-02-25 19:44:06 -05:00
parent 711d16cc65
commit d4c6957e2d
4 changed files with 21 additions and 5 deletions

View File

@@ -13,6 +13,12 @@ function foo(arg: number | Ref<number>) {
// ref unwrapping
expectType<number>(unref(arg))
// ref inner type should be unwrapped
const nestedRef = ref({
foo: ref(1)
})
expectType<Ref<{ foo: number }>>(nestedRef)
}
foo(1)

View File

@@ -52,3 +52,13 @@ watch(
},
{ immediate: true }
)
// should provide correct ref.value inner type to callbacks
const nestedRefSource = ref({
foo: ref(1)
})
watch(nestedRefSource, (v, ov) => {
expectType<{ foo: number }>(v)
expectType<{ foo: number }>(ov)
})