Skip to content

Commit

Permalink
feat: support inject key types (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawtim committed Aug 15, 2023
1 parent 06357e7 commit 599423c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions src/apis/inject.ts
Expand Up @@ -17,10 +17,8 @@ function resolveInject(
): any {
let source = vm
while (source) {
// @ts-ignore
if (source._provided && hasOwn(source._provided, provideKey)) {
//@ts-ignore
return source._provided[provideKey]
if (source._provided && hasOwn(source._provided, provideKey as PropertyKey)) {
return source._provided[provideKey as PropertyKey]
}
source = source.$parent
}
Expand All @@ -29,7 +27,7 @@ function resolveInject(
}

export function provide<T>(key: InjectionKey<T> | string, value: T): void {
const vm: any = getCurrentInstanceForFn('provide')?.proxy
const vm = getCurrentInstanceForFn('provide')?.proxy
if (!vm) return

if (!vm._provided) {
Expand Down
1 change: 1 addition & 0 deletions src/env.d.ts
Expand Up @@ -13,6 +13,7 @@ declare module 'vue/types/vue' {
readonly _uid: number
readonly _data: Record<string, any>
_watchers: VueWatcher[]
_provided: Record<PropertyKey, any>
__composition_api_state__?: VfaState
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/utils.ts
Expand Up @@ -36,7 +36,7 @@ export function def(obj: Object, key: string, val: any, enumerable?: boolean) {
})
}

export function hasOwn(obj: Object, key: string): boolean {
export function hasOwn(obj: Object, key: PropertyKey): boolean {
return Object.hasOwnProperty.call(obj, key)
}

Expand Down

0 comments on commit 599423c

Please sign in to comment.