Skip to content

Commit

Permalink
fix(types): improve type of unref()
Browse files Browse the repository at this point in the history
fix #3954
  • Loading branch information
yyx990803 committed Jul 1, 2021
1 parent 69b74a8 commit 127ed1b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/reactivity/src/ref.ts
Expand Up @@ -85,7 +85,7 @@ export function triggerRef(ref: Ref) {
trigger(toRaw(ref), TriggerOpTypes.SET, 'value', __DEV__ ? ref.value : void 0)
}

export function unref<T>(ref: T): T extends Ref<infer V> ? V : T {
export function unref<T>(ref: T | Ref<T>): T {
return isRef(ref) ? (ref.value as any) : ref
}

Expand Down
7 changes: 7 additions & 0 deletions test-dts/ref.test-d.ts
Expand Up @@ -203,3 +203,10 @@ switch (data.state.value) {
data.state.value = 'state1'
break
}

// #3954
function testUnrefGenerics<T>(p: T | Ref<T>) {
expectType<T>(unref(p))
}

testUnrefGenerics(1)

0 comments on commit 127ed1b

Please sign in to comment.