]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
types: improve readability of built-in type (#9129)
authorAlex Liu <dsa1314@gmail.com>
Thu, 30 May 2024 11:41:38 +0000 (19:41 +0800)
committerGitHub <noreply@github.com>
Thu, 30 May 2024 11:41:38 +0000 (19:41 +0800)
packages/reactivity/src/reactive.ts
packages/reactivity/src/ref.ts
packages/runtime-core/src/compat/instance.ts

index a3e7ecc7b56e651b1ea28e6287bbbd4a617573a8..6e28be404fa24551fe3c09e9b9b1f79a07caf843 100644 (file)
@@ -135,7 +135,7 @@ export function shallowReactive<T extends object>(
 }
 
 type Primitive = string | number | boolean | bigint | symbol | undefined | null
-type Builtin = Primitive | Function | Date | Error | RegExp
+export type Builtin = Primitive | Function | Date | Error | RegExp
 export type DeepReadonly<T> = T extends Builtin
   ? T
   : T extends Map<infer K, infer V>
index bd121e47d465cfe713d601e63c8704f9e32696d3..99170d154ba8f62b15cd196d125a8a74f574e58e 100644 (file)
@@ -21,7 +21,7 @@ import {
   toRaw,
   toReactive,
 } from './reactive'
-import type { ShallowReactiveMarker } from './reactive'
+import type { Builtin, ShallowReactiveMarker } from './reactive'
 import { type Dep, createDep } from './dep'
 import { ComputedRefImpl } from './computed'
 import { getDepFromReactive } from './reactiveEffect'
@@ -475,11 +475,6 @@ function propertyToRef(
     : (new ObjectRefImpl(source, key, defaultValue) as any)
 }
 
-// corner case when use narrows type
-// Ex. type RelativePath = string & { __brand: unknown }
-// RelativePath extends object -> true
-type BaseTypes = string | number | boolean
-
 /**
  * This is a special exported interface for other packages to declare
  * additional types that should bail out for ref unwrapping. For example
@@ -509,8 +504,7 @@ export type UnwrapRef<T> =
       : UnwrapRefSimple<T>
 
 export type UnwrapRefSimple<T> = T extends
-  | Function
-  | BaseTypes
+  | Builtin
   | Ref
   | RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
   | { [RawSymbol]?: true }
index 7b89c5ad61ce23ea6297cd407180f1e09dfd800c..3fa7b454c797ac0f5c1ef909d8ca5ae82eff55e1 100644 (file)
@@ -46,11 +46,11 @@ export interface LegacyPublicProperties {
   $set<T extends Record<keyof any, any>, K extends keyof T>(
     target: T,
     key: K,
-    value: T[K]
+    value: T[K],
   ): void
   $delete<T extends Record<keyof any, any>, K extends keyof T>(
     target: T,
-    key: K
+    key: K,
   ): void
   $mount(el?: string | Element): this
   $destroy(): void