2
0
Shun Miyazawa 1 жил өмнө
parent
commit
1ae31decc8

+ 2 - 2
apps/app/src/stores/user.tsx

@@ -1,4 +1,4 @@
-import type { IGrantedGroup, IUserHasId } from '@growi/core';
+import type { IGrantedGroup, IUserHasId, Populated } from '@growi/core';
 import type { SWRResponse } from 'swr';
 import useSWR from 'swr';
 import useSWRImmutable from 'swr/immutable';
@@ -51,7 +51,7 @@ export const useSWRxUsernames = (q: string, offset?: number, limit?: number, opt
 };
 
 type RelatedGroupsResponse = {
-  relatedGroups: IGrantedGroup[]
+  relatedGroups: Populated<IGrantedGroup, 'item'>[]
 }
 
 export const useSWRxUserRelatedGroups = (): SWRResponse<RelatedGroupsResponse, Error> => {

+ 10 - 0
packages/core/src/interfaces/common.ts

@@ -11,6 +11,16 @@ type ObjectId = Types.ObjectId;
 // Foreign key field
 export type Ref<T> = string | ObjectId | T & { _id: string | ObjectId };
 
+export type Populated<T, K extends keyof T> = {
+  [P in keyof T]: P extends K
+    ? T[P] extends null
+      ? null
+      : T[P] extends Ref<infer R>
+        ? R
+        : T[P]
+    : T[P];
+};
+
 export type Nullable<T> = T | null | undefined;
 
 export const isRef = <T>(obj: unknown): obj is Ref<T> => {