From f8994da00f523d5d792997671f4f55eca43d6598 Mon Sep 17 00:00:00 2001 From: Alex Liu Date: Thu, 30 May 2024 19:41:38 +0800 Subject: [PATCH] types: improve readability of built-in type (#9129) --- packages/reactivity/src/reactive.ts | 2 +- packages/reactivity/src/ref.ts | 10 ++-------- packages/runtime-core/src/compat/instance.ts | 4 ++-- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index a3e7ecc7b56..6e28be404fa 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -135,7 +135,7 @@ export function shallowReactive( } 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 extends Builtin ? T : T extends Map diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index bd121e47d46..99170d154ba 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -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 = : UnwrapRefSimple export type UnwrapRefSimple = T extends - | Function - | BaseTypes + | Builtin | Ref | RefUnwrapBailTypes[keyof RefUnwrapBailTypes] | { [RawSymbol]?: true } diff --git a/packages/runtime-core/src/compat/instance.ts b/packages/runtime-core/src/compat/instance.ts index 7b89c5ad61c..3fa7b454c79 100644 --- a/packages/runtime-core/src/compat/instance.ts +++ b/packages/runtime-core/src/compat/instance.ts @@ -46,11 +46,11 @@ export interface LegacyPublicProperties { $set, K extends keyof T>( target: T, key: K, - value: T[K] + value: T[K], ): void $delete, K extends keyof T>( target: T, - key: K + key: K, ): void $mount(el?: string | Element): this $destroy(): void