Skip to content

Commit 599423c

Browse files
authored
feat: support inject key types (#986)
1 parent 06357e7 commit 599423c

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

Diff for: pnpm-lock.yaml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/apis/inject.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ function resolveInject(
1717
): any {
1818
let source = vm
1919
while (source) {
20-
// @ts-ignore
21-
if (source._provided && hasOwn(source._provided, provideKey)) {
22-
//@ts-ignore
23-
return source._provided[provideKey]
20+
if (source._provided && hasOwn(source._provided, provideKey as PropertyKey)) {
21+
return source._provided[provideKey as PropertyKey]
2422
}
2523
source = source.$parent
2624
}
@@ -29,7 +27,7 @@ function resolveInject(
2927
}
3028

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

3533
if (!vm._provided) {

Diff for: src/env.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ declare module 'vue/types/vue' {
1313
readonly _uid: number
1414
readonly _data: Record<string, any>
1515
_watchers: VueWatcher[]
16+
_provided: Record<PropertyKey, any>
1617
__composition_api_state__?: VfaState
1718
}
1819

Diff for: src/utils/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function def(obj: Object, key: string, val: any, enumerable?: boolean) {
3636
})
3737
}
3838

39-
export function hasOwn(obj: Object, key: string): boolean {
39+
export function hasOwn(obj: Object, key: PropertyKey): boolean {
4040
return Object.hasOwnProperty.call(obj, key)
4141
}
4242

0 commit comments

Comments
 (0)