From 8696f4ee705c9ccdf6c3dd3eb40e2836911a4e84 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 19 Feb 2021 19:38:47 +0800 Subject: [PATCH] types(utils): pick type (#8179) --- src/action-sheet/index.tsx | 4 +++- src/dialog/Dialog.tsx | 4 ++-- src/search/index.tsx | 2 +- src/utils/base.ts | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/action-sheet/index.tsx b/src/action-sheet/index.tsx index 5cc001473..7ae296d37 100644 --- a/src/action-sheet/index.tsx +++ b/src/action-sheet/index.tsx @@ -50,7 +50,9 @@ export default createComponent({ emits: ['select', 'cancel', 'update:show'], setup(props, { slots, emit }) { - const popupPropKeys = Object.keys(popupSharedProps); + const popupPropKeys = Object.keys(popupSharedProps) as Array< + keyof typeof popupSharedProps + >; const onUpdateShow = (show: boolean) => { emit('update:show', show); diff --git a/src/dialog/Dialog.tsx b/src/dialog/Dialog.tsx index ddf29569e..65490b28a 100644 --- a/src/dialog/Dialog.tsx +++ b/src/dialog/Dialog.tsx @@ -18,10 +18,10 @@ export type DialogAction = 'confirm' | 'cancel'; export type DialogMessageAlign = 'left' | 'center' | 'right'; const popupKeys = [ - ...Object.keys(popupSharedProps), + ...(Object.keys(popupSharedProps) as Array), 'transition', 'closeOnPopstate', -]; +] as const; export default createComponent({ props: { diff --git a/src/search/index.tsx b/src/search/index.tsx index ee90bcc72..c810c8c73 100644 --- a/src/search/index.tsx +++ b/src/search/index.tsx @@ -105,7 +105,7 @@ export default createComponent({ 'clearable', 'modelValue', 'clearTrigger', - ]; + ] as const; const renderField = () => { const fieldAttrs = { diff --git a/src/utils/base.ts b/src/utils/base.ts index 4e1c97aac..e6306ff92 100644 --- a/src/utils/base.ts +++ b/src/utils/base.ts @@ -38,9 +38,9 @@ export function get(object: any, path: string): any { return result; } -export function pick(obj: Record, keys: string[]) { +export function pick(obj: T, keys: ReadonlyArray) { return keys.reduce((ret, key) => { ret[key] = obj[key]; return ret; - }, {} as Record); + }, {} as Pick); }