Skip to content

Commit

Permalink
refactor: better types
Browse files Browse the repository at this point in the history
  • Loading branch information
posva authored and yyx990803 committed Apr 5, 2023
1 parent b233bbf commit 2b3e6c6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/runtime-core/src/apiInject.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { isFunction } from '@vue/shared'
import { currentInstance } from './component'
import { currentRenderingInstance } from './componentRenderContext'
import { App, currentApp } from './apiCreateApp'
import { currentApp } from './apiCreateApp'
import { warn } from './warning'
import { ComponentPublicInstance } from './componentPublicInstance'

export interface InjectionKey<T> extends Symbol {}

Expand Down Expand Up @@ -64,7 +65,9 @@ export function inject(
return provides[key as string]
} else if (arguments.length > 1) {
return treatDefaultAsFactory && isFunction(defaultValue)
? defaultValue.call((instance as App & { proxy: undefined }).proxy)
? defaultValue.call(
(instance as { proxy?: ComponentPublicInstance | null }).proxy
)
: defaultValue
} else if (__DEV__) {
warn(`injection "${String(key)}" not found.`)
Expand Down

0 comments on commit 2b3e6c6

Please sign in to comment.