Skip to content

Commit

Permalink
fix(types): allow using InjectionKey as valid property key
Browse files Browse the repository at this point in the history
close #5089
  • Loading branch information
yyx990803 committed Aug 2, 2024
1 parent 1fbfa69 commit 321d807
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/dts-test/inject.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
type InjectionKey,
type Ref,
createApp,
defineComponent,
inject,
provide,
ref,
Expand Down Expand Up @@ -52,3 +53,9 @@ provide<Cube>(123, { size: 'foo' })
const app = createApp({})
// @ts-expect-error
app.provide(injectionKeyRef, ref({}))

defineComponent({
provide: {
[injectionKeyRef]: { size: 'foo' },
},
})
4 changes: 3 additions & 1 deletion packages/runtime-core/src/apiInject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 321d807

Please sign in to comment.