Skip to content

Commit

Permalink
fix(types): improve app.provide type checking (#10603)
Browse files Browse the repository at this point in the history
close #10602
  • Loading branch information
makedopamine authored Jun 10, 2024
1 parent aae2d78 commit 612bbf0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit 612bbf0

Please sign in to comment.