]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types): fix ref(false) type to Ref<boolean> (#1028)
authorCarlos Rodrigues <carlos@hypermob.co.uk>
Wed, 22 Apr 2020 15:54:54 +0000 (16:54 +0100)
committerGitHub <noreply@github.com>
Wed, 22 Apr 2020 15:54:54 +0000 (11:54 -0400)
packages/reactivity/src/ref.ts
test-dts/ref.test-d.ts

index 5b26aec108bbffe2cbbe52de4ecfe38b21a72423..79c2dc52c2ab741061bdc0ea368b71497a91fe20 100644 (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)
index 7aa6c606637ce5e06948102e23a246272c54cefa..41dc6ee75c47cc376f30ce2d553bc2c1c96bc185 100644 (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'])))