diff --git a/packages/runtime-core/src/apiInject.ts b/packages/runtime-core/src/apiInject.ts index 402113cd1b1..ae52b631ee6 100644 --- a/packages/runtime-core/src/apiInject.ts +++ b/packages/runtime-core/src/apiInject.ts @@ -23,23 +23,23 @@ export function provide(key: InjectionKey | string | number, value: T) { provides = currentInstance.provides = Object.create(parentProvides) } // TS doesn't allow symbol as index type - provides[key as string] = value + provides[key as string | number] = value } } -export function inject(key: InjectionKey | string): T | undefined +export function inject(key: InjectionKey | string | number): T | undefined export function inject( - key: InjectionKey | string, + key: InjectionKey | string | number, defaultValue: T, treatDefaultAsFactory?: false ): T export function inject( - key: InjectionKey | string, + key: InjectionKey | string | number, defaultValue: T | (() => T), treatDefaultAsFactory: true ): T export function inject( - key: InjectionKey | string, + key: InjectionKey | string | number, defaultValue?: unknown, treatDefaultAsFactory = false ) { @@ -55,9 +55,9 @@ export function inject( ? instance.vnode.appContext && instance.vnode.appContext.provides : instance.parent.provides - if (provides && (key as string | symbol) in provides) { + if (provides && (key as string | symbol | number) in provides) { // TS doesn't allow symbol as index type - return provides[key as string] + return provides[key as string | number] } else if (arguments.length > 1) { return treatDefaultAsFactory && isFunction(defaultValue) ? defaultValue()