From f2124251ed39d5afcb3bd685e6d4d8465229dc72 Mon Sep 17 00:00:00 2001 From: cexbrayat Date: Thu, 28 Jan 2021 17:16:56 +0100 Subject: [PATCH] fix(runtime-core): InjectionKey compatible with symbol type The current type of `InjectionKey` does not allow to use it as an ES computed property. This is problematic as the API of `mount` in VTU lets you add providers with `provide: { key: value }`. If you want to use a key defined as: export const storeKey: InjectionKey> = Symbol(); Then you currently have to cast the key as symbol: const wrapper = mount(App, { global: { provide: { [storeKey as symbol]: store } } }); This commit allows to use: const wrapper = mount(AppWithVuex, { global: { provide: { [storeKey]: store } } }); --- packages/runtime-core/src/apiInject.ts | 2 +- test-dts/inject.test-d.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/src/apiInject.ts b/packages/runtime-core/src/apiInject.ts index 402113cd1b1..678e41d2060 100644 --- a/packages/runtime-core/src/apiInject.ts +++ b/packages/runtime-core/src/apiInject.ts @@ -3,7 +3,7 @@ import { currentInstance } from './component' import { currentRenderingInstance } from './componentRenderUtils' import { warn } from './warning' -export interface InjectionKey extends Symbol {} +export type InjectionKey = symbol export function provide(key: InjectionKey | string | number, value: T) { if (!currentInstance) { diff --git a/test-dts/inject.test-d.ts b/test-dts/inject.test-d.ts index 69e06f170af..6653e03ea80 100644 --- a/test-dts/inject.test-d.ts +++ b/test-dts/inject.test-d.ts @@ -13,3 +13,6 @@ expectType(inject(key, () => 1, true /* treatDefaultAsFactory */)) expectType<() => number>(inject('foo', () => 1)) expectType<() => number>(inject('foo', () => 1, false)) expectType(inject('foo', () => 1, true)) + +// InjectionKey should be compatible with the `symbol` type +expectType>({ [key]: 2 })