Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: improve readability of built-in type #9129

Merged
merged 11 commits into from
May 30, 2024
2 changes: 1 addition & 1 deletion packages/reactivity/src/reactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Mini-ghost marked this conversation as resolved.
Show resolved Hide resolved
export type DeepReadonly<T> = T extends Builtin
? T
: T extends Map<infer K, infer V>
Expand Down
10 changes: 2 additions & 8 deletions packages/reactivity/src/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-core/src/compat/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down