Explorar o código

fix(types): allow using InjectionKey as valid property key

close #5089
Evan You hai 1 ano
pai
achega
321d80758c
Modificáronse 2 ficheiros con 10 adicións e 1 borrados
  1. 7 0
      packages/dts-test/inject.test-d.ts
  2. 3 1
      packages/runtime-core/src/apiInject.ts

+ 7 - 0
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<Cube>(123, { size: 'foo' })
 const app = createApp({})
 // @ts-expect-error
 app.provide(injectionKeyRef, ref({}))
+
+defineComponent({
+  provide: {
+    [injectionKeyRef]: { size: 'foo' },
+  },
+})

+ 3 - 1
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<T> extends Symbol {}
+interface InjectionConstraint<T> {}
+
+export type InjectionKey<T> = symbol & InjectionConstraint<T>
 
 export function provide<T, K = InjectionKey<T> | string | number>(
   key: K,