Browse Source

chore: use PropertyKey type (#11056)

close #8559
tomasvn 1 year ago
parent
commit
32262a9af5

+ 1 - 1
packages/reactivity/src/reactiveEffect.ts

@@ -145,7 +145,7 @@ export function trigger(
   resetScheduling()
 }
 
-export function getDepFromReactive(object: any, key: string | number | symbol) {
+export function getDepFromReactive(object: any, key: PropertyKey) {
   const depsMap = targetMap.get(object)
   return depsMap && depsMap.get(key)
 }

+ 7 - 7
packages/runtime-core/src/apiSetupHelpers.ts

@@ -215,7 +215,7 @@ export function defineSlots<
   return null as any
 }
 
-export type ModelRef<T, M extends string | number | symbol = string> = Ref<T> &
+export type ModelRef<T, M extends PropertyKey = string> = Ref<T> &
   [ModelRef<T, M>, Record<M, true | undefined>]
 
 export type DefineModelOptions<T = any> = {
@@ -256,24 +256,24 @@ export type DefineModelOptions<T = any> = {
  * const count = defineModel<number>('count', { default: 0 })
  * ```
  */
-export function defineModel<T, M extends string | number | symbol = string>(
+export function defineModel<T, M extends PropertyKey = string>(
   options: { required: true } & PropOptions<T> & DefineModelOptions<T>,
 ): ModelRef<T, M>
-export function defineModel<T, M extends string | number | symbol = string>(
+export function defineModel<T, M extends PropertyKey = string>(
   options: { default: any } & PropOptions<T> & DefineModelOptions<T>,
 ): ModelRef<T, M>
-export function defineModel<T, M extends string | number | symbol = string>(
+export function defineModel<T, M extends PropertyKey = string>(
   options?: PropOptions<T> & DefineModelOptions<T>,
 ): ModelRef<T | undefined, M>
-export function defineModel<T, M extends string | number | symbol = string>(
+export function defineModel<T, M extends PropertyKey = string>(
   name: string,
   options: { required: true } & PropOptions<T> & DefineModelOptions<T>,
 ): ModelRef<T, M>
-export function defineModel<T, M extends string | number | symbol = string>(
+export function defineModel<T, M extends PropertyKey = string>(
   name: string,
   options: { default: any } & PropOptions<T> & DefineModelOptions<T>,
 ): ModelRef<T, M>
-export function defineModel<T, M extends string | number | symbol = string>(
+export function defineModel<T, M extends PropertyKey = string>(
   name: string,
   options?: PropOptions<T> & DefineModelOptions<T>,
 ): ModelRef<T | undefined, M>

+ 2 - 2
packages/runtime-core/src/compat/global.ts

@@ -102,11 +102,11 @@ export type CompatVue = Pick<App, 'version' | 'component' | 'directive'> & {
   /**
    * @deprecated Vue 3 no longer needs set() for adding new properties.
    */
-  set(target: any, key: string | number | symbol, value: any): void
+  set(target: any, key: PropertyKey, value: any): void
   /**
    * @deprecated Vue 3 no longer needs delete() for property deletions.
    */
-  delete(target: any, key: string | number | symbol): void
+  delete(target: any, key: PropertyKey): void
   /**
    * @deprecated use `reactive` instead.
    */

+ 1 - 1
packages/runtime-core/src/components/KeepAlive.ts

@@ -55,7 +55,7 @@ export interface KeepAliveProps {
   max?: number | string
 }
 
-type CacheKey = string | number | symbol | ConcreteComponent
+type CacheKey = PropertyKey | ConcreteComponent
 type Cache = Map<CacheKey, VNode>
 type Keys = Set<CacheKey>
 

+ 1 - 1
packages/runtime-core/src/helpers/useModel.ts

@@ -7,7 +7,7 @@ import type { NormalizedProps } from '../componentProps'
 import { watchSyncEffect } from '../apiWatch'
 
 export function useModel<
-  M extends string | number | symbol,
+  M extends PropertyKey,
   T extends Record<string, any>,
   K extends keyof T,
 >(props: T, name: K, options?: DefineModelOptions<T[K]>): ModelRef<T[K], M>

+ 1 - 1
packages/runtime-core/src/renderer.ts

@@ -1908,7 +1908,7 @@ function baseCreateRenderer(
       const s2 = i // next starting index
 
       // 5.1 build key:index map for newChildren
-      const keyToNewIndexMap: Map<string | number | symbol, number> = new Map()
+      const keyToNewIndexMap: Map<PropertyKey, number> = new Map()
       for (i = s2; i <= e2; i++) {
         const nextChild = (c2[i] = optimized
           ? cloneIfMounted(c2[i] as VNode)

+ 2 - 2
packages/runtime-core/src/vnode.ts

@@ -112,7 +112,7 @@ export type VNodeHook =
 
 // https://github.com/microsoft/TypeScript/issues/33099
 export type VNodeProps = {
-  key?: string | number | symbol
+  key?: PropertyKey
   ref?: VNodeRef
   ref_for?: boolean
   ref_key?: string
@@ -162,7 +162,7 @@ export interface VNode<
 
   type: VNodeTypes
   props: (VNodeProps & ExtraProps) | null
-  key: string | number | symbol | null
+  key: PropertyKey | null
   ref: VNodeNormalizedRef | null
   /**
    * SFC only. This is assigned on vnode creation using currentScopeId

+ 1 - 1
packages/runtime-dom/src/jsx.ts

@@ -1390,7 +1390,7 @@ type EventHandlers<E> = {
 import type { VNodeRef } from '@vue/runtime-core'
 
 export type ReservedProps = {
-  key?: string | number | symbol
+  key?: PropertyKey
   ref?: VNodeRef
   ref_for?: boolean
   ref_key?: string