Browse Source

improve isPopulated

Yuki Takei 1 năm trước cách đây
mục cha
commit
5fc7a4705b
1 tập tin đã thay đổi với 4 bổ sung2 xóa
  1. 4 2
      packages/core/src/interfaces/common.ts

+ 4 - 2
packages/core/src/interfaces/common.ts

@@ -3,7 +3,7 @@
  */
 
 
-import { Types } from 'mongoose';
+import type { Types } from 'mongoose';
 
 type ObjectId = Types.ObjectId;
 
@@ -13,7 +13,9 @@ export type Ref<T> = string | ObjectId | T & { _id: string | ObjectId };
 export type Nullable<T> = T | null | undefined;
 
 export const isPopulated = <T>(ref: Ref<T>): ref is T & { _id: string | ObjectId } => {
-  return ref != null && typeof ref !== 'string' && !(ref instanceof Types.ObjectId);
+  return ref != null
+    && typeof ref !== 'string'
+    && !('_bsontype' in ref && ref._bsontype === 'ObjectID');
 };
 
 export const getIdForRef = <T>(ref: Ref<T>): string | ObjectId => {