Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): fix app.provide type checking #10603

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/dts-test/inject.test-d.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -40,3 +47,8 @@ provide<Cube>(injectionKeyRef, { size: 123 })
provide<Cube>('cube', { size: 'foo' })
// @ts-expect-error
provide<Cube>(123, { size: 'foo' })

// #10602
const app = createApp({})
// @ts-expect-error
app.provide(injectionKeyRef, ref({}))
5 changes: 4 additions & 1 deletion packages/runtime-core/src/apiCreateApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ export interface App<HostElement = any> {
namespace?: boolean | ElementNamespace,
): ComponentPublicInstance
unmount(): void
provide<T>(key: InjectionKey<T> | string, value: T): this
provide<T, K = InjectionKey<T> | string | number>(
key: K,
value: K extends InjectionKey<infer V> ? V : T,
): this

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