core
core copied to clipboard
fix(types): reactive collection type is not as expected (#5954)
fix: https://github.com/vuejs/core/issues/5954
When we explicitly declare the type for the argument to the reactive function:
interface WrapRef {
foo: Ref<number>
}
const obj = reactive<WrapRef>({
foo: ref(1)
})
const map = reactive(new Map<string, WrapRef>())
map.set('a', {
foo: ref(1)
})
The types of the map and set methods at this point are:
interface Map<K, V>{
set(key: K, value: V): this;
}
I think the type of map as Map<string, WrapRef> is as expected.
The problem is that when using map.get to get a value, the ref value will automatically unref. So it is possible to handle it from the get method.
Deploy Preview for vuejs-coverage failed.
| Name | Link |
|---|---|
| Latest commit | 13f636677af9f453a297d90e2125ae2b661813b5 |
| Latest deploy log | https://app.netlify.com/sites/vuejs-coverage/deploys/62debe7b8dcbec00081c8b34 |
The type checking from vscode is fine, but running pnpm run test-dts-only doesn't pass the type checking in tsconfig.build.json, so I'll see what the problem is tomorrow, and I'm going to bed now in order for k to work properly tomorrow.
Writing declare global in a file is not visible to the user, which is somewhat problematic here.