Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 612bbf0

Browse files
authored
fix(types): improve app.provide type checking (#10603)
close #10602
1 parent aae2d78 commit 612bbf0

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/dts-test/inject.test-d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { type InjectionKey, type Ref, inject, provide, ref } from 'vue'
1+
import {
2+
type InjectionKey,
3+
type Ref,
4+
createApp,
5+
inject,
6+
provide,
7+
ref,
8+
} from 'vue'
29
import { expectType } from './utils'
310

411
// non-symbol keys
@@ -40,3 +47,8 @@ provide<Cube>(injectionKeyRef, { size: 123 })
4047
provide<Cube>('cube', { size: 'foo' })
4148
// @ts-expect-error
4249
provide<Cube>(123, { size: 'foo' })
50+
51+
// #10602
52+
const app = createApp({})
53+
// @ts-expect-error
54+
app.provide(injectionKeyRef, ref({}))

packages/runtime-core/src/apiCreateApp.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ export interface App<HostElement = any> {
5050
namespace?: boolean | ElementNamespace,
5151
): ComponentPublicInstance
5252
unmount(): void
53-
provide<T>(key: InjectionKey<T> | string, value: T): this
53+
provide<T, K = InjectionKey<T> | string | number>(
54+
key: K,
55+
value: K extends InjectionKey<infer V> ? V : T,
56+
): this
5457

5558
/**
5659
* Runs a function with the app as active instance. This allows using of `inject()` within the function to get access

0 commit comments

Comments
 (0)