소스 검색

changed not to use type assertion

WNomunomu 2 년 전
부모
커밋
234a5ded6c
1개의 변경된 파일6개의 추가작업 그리고 6개의 파일을 삭제
  1. 6 6
      apps/app/src/server/service/in-app-notification/in-app-notification-utils.ts

+ 6 - 6
apps/app/src/server/service/in-app-notification/in-app-notification-utils.ts

@@ -3,16 +3,16 @@ import type { IUser, IPage } from '@growi/core';
 import { SupportedTargetModel } from '~/interfaces/activity';
 import * as pageSerializers from '~/models/serializers/in-app-notification-snapshot/page';
 
+const isIPage = (targetModel: string, target: IUser | IPage): target is IPage => {
+  return targetModel === SupportedTargetModel.MODEL_PAGE;
+};
+
 export const generateSnapshot = (targetModel: string, target: IUser | IPage) => {
 
   let snapshot;
 
-  switch (targetModel) {
-    case SupportedTargetModel.MODEL_PAGE:
-      snapshot = pageSerializers.stringifySnapshot(target as IPage);
-      break;
-    default:
-      break;
+  if (isIPage(targetModel, target)) {
+    snapshot = pageSerializers.stringifySnapshot(target);
   }
 
   return snapshot;