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

close #5089
This commit is contained in:
Evan You 2024-08-02 11:11:03 +08:00
parent 1fbfa6962b
commit 321d80758c
No known key found for this signature in database
GPG Key ID: 00E9AB7A6704CE0A
2 changed files with 10 additions and 1 deletions

View File

@ -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' },
},
})

View File

@ -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,