diff --git a/packages/dts-test/inject.test-d.ts b/packages/dts-test/inject.test-d.ts index 55116f5692e..2e8341ff0ae 100644 --- a/packages/dts-test/inject.test-d.ts +++ b/packages/dts-test/inject.test-d.ts @@ -1,4 +1,11 @@ -import { type InjectionKey, type Ref, inject, provide, ref } from 'vue' +import { + type InjectionKey, + type Ref, + createApp, + inject, + provide, + ref, +} from 'vue' import { expectType } from './utils' // non-symbol keys @@ -40,3 +47,8 @@ provide(injectionKeyRef, { size: 123 }) provide('cube', { size: 'foo' }) // @ts-expect-error provide(123, { size: 'foo' }) + +// #10602 +const app = createApp({}) +// @ts-expect-error +app.provide(injectionKeyRef, ref({})) diff --git a/packages/runtime-core/src/apiCreateApp.ts b/packages/runtime-core/src/apiCreateApp.ts index 65c10166de7..b7eb399f727 100644 --- a/packages/runtime-core/src/apiCreateApp.ts +++ b/packages/runtime-core/src/apiCreateApp.ts @@ -50,7 +50,10 @@ export interface App { namespace?: boolean | ElementNamespace, ): ComponentPublicInstance unmount(): void - provide(key: InjectionKey | string, value: T): this + provide | string | number>( + key: K, + value: K extends InjectionKey ? V : T, + ): this /** * Runs a function with the app as active instance. This allows using of `inject()` within the function to get access