Skip to content

Commit

Permalink
fix(types): fix ref(false) type to Ref<boolean> (vuejs#1028)
Browse files Browse the repository at this point in the history
  • Loading branch information
pikax committed Apr 29, 2020
1 parent 3f12f8f commit 899486b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/reactivity/src/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions test-dts/ref.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'])))

Expand Down

0 comments on commit 899486b

Please sign in to comment.