From 321d80758c42fccbd39ecbb63f1a4f6632a1580a Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 2 Aug 2024 11:11:03 +0800 Subject: [PATCH] fix(types): allow using InjectionKey as valid property key close #5089 --- packages/dts-test/inject.test-d.ts | 7 +++++++ packages/runtime-core/src/apiInject.ts | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/dts-test/inject.test-d.ts b/packages/dts-test/inject.test-d.ts index 2e8341ff0..e545ef623 100644 --- a/packages/dts-test/inject.test-d.ts +++ b/packages/dts-test/inject.test-d.ts @@ -2,6 +2,7 @@ import { type InjectionKey, type Ref, createApp, + defineComponent, inject, provide, ref, @@ -52,3 +53,9 @@ provide(123, { size: 'foo' }) const app = createApp({}) // @ts-expect-error app.provide(injectionKeyRef, ref({})) + +defineComponent({ + provide: { + [injectionKeyRef]: { size: 'foo' }, + }, +}) diff --git a/packages/runtime-core/src/apiInject.ts b/packages/runtime-core/src/apiInject.ts index f15983604..06d39b61a 100644 --- a/packages/runtime-core/src/apiInject.ts +++ b/packages/runtime-core/src/apiInject.ts @@ -4,7 +4,9 @@ import { currentRenderingInstance } from './componentRenderContext' import { currentApp } from './apiCreateApp' import { warn } from './warning' -export interface InjectionKey extends Symbol {} +interface InjectionConstraint {} + +export type InjectionKey = symbol & InjectionConstraint export function provide | string | number>( key: K,