Explorar o código

improve types for search

Yuki Takei hai 6 meses
pai
achega
f852295917

+ 1 - 1
apps/app/src/features/search/client/components/SearchPage/SearchResultList.tsx

@@ -104,7 +104,7 @@ const SearchResultListSubstance: ForwardRefRenderFunction<
           ...page.meta,
           ...page.meta,
           ...pageInfo,
           ...pageInfo,
         },
         },
-      } as IPageWithMeta<IPageInfoForListing & IPageSearchMeta>;
+      } satisfies IPageWithMeta<IPageInfoForListing & IPageSearchMeta>;
     });
     });
   }
   }
 
 

+ 13 - 12
apps/app/src/interfaces/search.ts

@@ -1,4 +1,8 @@
-import type { IDataWithMeta, IPageHasId } from '@growi/core';
+import type {
+  IDataWithMeta,
+  IDataWithRequiredMeta,
+  IPageHasId,
+} from '@growi/core';
 
 
 export type IPageSearchMeta = {
 export type IPageSearchMeta = {
   bookmarkCount?: number;
   bookmarkCount?: number;
@@ -14,11 +18,9 @@ export const isIPageSearchMeta = (meta: any): meta is IPageSearchMeta => {
 };
 };
 
 
 export type ISearchResultMeta = {
 export type ISearchResultMeta = {
-  meta: {
-    took?: number;
-    total: number;
-    hitsCount: number;
-  };
+  took?: number;
+  total: number;
+  hitsCount: number;
 };
 };
 
 
 export type ISearchResultData = {
 export type ISearchResultData = {
@@ -28,15 +30,14 @@ export type ISearchResultData = {
   _highlight: any;
   _highlight: any;
 };
 };
 
 
-export type ISearchResult<T> = ISearchResultMeta & {
-  data: T[];
-};
+export type ISearchResult<T> = IDataWithRequiredMeta<T[], ISearchResultMeta>;
 
 
 export type IPageWithSearchMeta = IDataWithMeta<IPageHasId, IPageSearchMeta>;
 export type IPageWithSearchMeta = IDataWithMeta<IPageHasId, IPageSearchMeta>;
 
 
-export type IFormattedSearchResult = ISearchResultMeta & {
-  data: IPageWithSearchMeta[];
-};
+export type IFormattedSearchResult = IDataWithRequiredMeta<
+  IPageWithSearchMeta[],
+  ISearchResultMeta
+>;
 
 
 export const SORT_AXIS = {
 export const SORT_AXIS = {
   RELATION_SCORE: 'relationScore',
   RELATION_SCORE: 'relationScore',