fix(types): improve ref typing, close #759
This commit is contained in:
16
test-dts/ref.test-d.ts
Normal file
16
test-dts/ref.test-d.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { expectType } from 'tsd'
|
||||
import { Ref, ref } from './index'
|
||||
import { isRef } from '@vue/reactivity'
|
||||
|
||||
function foo(arg: number | Ref<number>) {
|
||||
// ref coercing
|
||||
const coerced = ref(arg)
|
||||
expectType<Ref<number>>(coerced)
|
||||
|
||||
// isRef as type guard
|
||||
if (isRef(arg)) {
|
||||
expectType<Ref<number>>(arg)
|
||||
}
|
||||
}
|
||||
|
||||
foo(1)
|
||||
Reference in New Issue
Block a user