fix(types): fix ref(false) type to Ref<boolean> (#1028)

This commit is contained in:
Carlos Rodrigues 2020-04-22 16:54:54 +01:00 committed by GitHub
parent e422b8b082
commit 0bdd889156
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -28,7 +28,10 @@ export function isRef(r: any): r is Ref {
return r ? r._isRef === true : false
}
export function ref<T>(value: T): T extends Ref ? T : Ref<UnwrapRef<T>>
export function ref<T extends object>(
value: T
): T extends Ref ? T : Ref<UnwrapRef<T>>
export function ref<T>(value: T): Ref<UnwrapRef<T>>
export function ref<T = any>(): Ref<T | undefined>
export function ref(value?: unknown) {
return createRef(value)

View File

@ -21,6 +21,16 @@ function plainType(arg: number | Ref<number>) {
expectType<Ref<{ foo: number }>>(nestedRef)
expectType<{ foo: number }>(nestedRef.value)
// ref boolean
const falseRef = ref(false)
expectType<Ref<boolean>>(falseRef)
expectType<boolean>(falseRef.value)
// ref true
const trueRef = ref<true>(true)
expectType<Ref<true>>(trueRef)
expectType<true>(trueRef.value)
// tuple
expectType<[number, string]>(unref(ref([1, '1'])))