types: improve readability of built-in type (#9129)

This commit is contained in:
Alex Liu 2024-05-30 19:41:38 +08:00 committed by GitHub
parent 70f2f283ee
commit f8994da00f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 11 deletions

View File

@ -135,7 +135,7 @@ export function shallowReactive<T extends object>(
} }
type Primitive = string | number | boolean | bigint | symbol | undefined | null 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 export type DeepReadonly<T> = T extends Builtin
? T ? T
: T extends Map<infer K, infer V> : T extends Map<infer K, infer V>

View File

@ -21,7 +21,7 @@ import {
toRaw, toRaw,
toReactive, toReactive,
} from './reactive' } from './reactive'
import type { ShallowReactiveMarker } from './reactive' import type { Builtin, ShallowReactiveMarker } from './reactive'
import { type Dep, createDep } from './dep' import { type Dep, createDep } from './dep'
import { ComputedRefImpl } from './computed' import { ComputedRefImpl } from './computed'
import { getDepFromReactive } from './reactiveEffect' import { getDepFromReactive } from './reactiveEffect'
@ -475,11 +475,6 @@ function propertyToRef(
: (new ObjectRefImpl(source, key, defaultValue) as any) : (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 * This is a special exported interface for other packages to declare
* additional types that should bail out for ref unwrapping. For example * additional types that should bail out for ref unwrapping. For example
@ -509,8 +504,7 @@ export type UnwrapRef<T> =
: UnwrapRefSimple<T> : UnwrapRefSimple<T>
export type UnwrapRefSimple<T> = T extends export type UnwrapRefSimple<T> = T extends
| Function | Builtin
| BaseTypes
| Ref | Ref
| RefUnwrapBailTypes[keyof RefUnwrapBailTypes] | RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
| { [RawSymbol]?: true } | { [RawSymbol]?: true }

View File

@ -46,11 +46,11 @@ export interface LegacyPublicProperties {
$set<T extends Record<keyof any, any>, K extends keyof T>( $set<T extends Record<keyof any, any>, K extends keyof T>(
target: T, target: T,
key: K, key: K,
value: T[K] value: T[K],
): void ): void
$delete<T extends Record<keyof any, any>, K extends keyof T>( $delete<T extends Record<keyof any, any>, K extends keyof T>(
target: T, target: T,
key: K key: K,
): void ): void
$mount(el?: string | Element): this $mount(el?: string | Element): this
$destroy(): void $destroy(): void