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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion packages/reactivity/src/reactive.ts
Expand Up @@ -141,7 +141,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
Expand Up @@ -16,7 +16,7 @@ import {
isReadonly,
isShallow
} from './reactive'
import type { ShallowReactiveMarker } from './reactive'
import type { Builtin, ShallowReactiveMarker } from './reactive'
import { createDep, Dep } from './dep'

declare const RefSymbol: unique symbol
Expand Down Expand Up @@ -452,11 +452,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 @@ -489,8 +484,7 @@ export type UnwrapRef<T> = T extends ShallowRef<infer V>
: UnwrapRefSimple<T>

export type UnwrapRefSimple<T> = T extends
| Function
| BaseTypes
| Builtin
| Ref
| RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
| { [RawSymbol]?: true }
Expand Down