From 6f8307b5a326d7f46fa73420c3f2aaf9bcfac4f9 Mon Sep 17 00:00:00 2001 From: hawtimzhang Date: Wed, 9 Aug 2023 12:39:42 +0800 Subject: [PATCH] feat: support inject key types --- pnpm-lock.yaml | 2 +- src/apis/inject.ts | 8 +++----- src/env.d.ts | 1 + src/utils/utils.ts | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 67e01ba3..a2ada191 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1000,8 +1000,8 @@ packages: engines: {node: '>=10'} hasBin: true dependencies: - is-text-path: 1.0.1 JSONStream: 1.3.5 + is-text-path: 1.0.1 lodash: 4.17.21 meow: 8.1.2 split2: 3.2.2 diff --git a/src/apis/inject.ts b/src/apis/inject.ts index 37ed881d..693b1920 100644 --- a/src/apis/inject.ts +++ b/src/apis/inject.ts @@ -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 } @@ -29,7 +27,7 @@ function resolveInject( } export function provide(key: InjectionKey | string, value: T): void { - const vm: any = getCurrentInstanceForFn('provide')?.proxy + const vm = getCurrentInstanceForFn('provide')?.proxy if (!vm) return if (!vm._provided) { diff --git a/src/env.d.ts b/src/env.d.ts index 8e362480..0433fb7a 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -13,6 +13,7 @@ declare module 'vue/types/vue' { readonly _uid: number readonly _data: Record _watchers: VueWatcher[] + _provided: Record __composition_api_state__?: VfaState } diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 9b715714..2f0a18b5 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -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) }