fix(types): fix ToRefs type on union value types

fix #2687
This commit is contained in:
Evan You
2020-12-02 14:58:03 -05:00
parent 24a7a2db6c
commit e315d84936
2 changed files with 30 additions and 3 deletions

View File

@@ -21,7 +21,11 @@ export interface Ref<T = any> {
}
export type ToRef<T> = T extends Ref ? T : Ref<UnwrapRef<T>>
export type ToRefs<T = any> = { [K in keyof T]: ToRef<T[K]> }
export type ToRefs<T = any> = {
// #2687: somehow using ToRef<T[K]> here turns the resulting type into
// a union of multiple Ref<*> types instead of a single Ref<* | *> type.
[K in keyof T]: T[K] extends Ref ? T[K] : Ref<UnwrapRef<T[K]>>
}
const convert = <T extends unknown>(val: T): T =>
isObject(val) ? reactive(val) : val