typescript - การตรวจสอบความเท่าเทียมของ ObjectID ของ MongoDB ด้วยลินต์
ฉันกำลังมองหาวิธีที่ดีในการป้องกันการเขียน objectId1 === objectId2 เมื่อตรวจสอบความเท่ากันของ MongoDB ObjectIds จะดีมากถ้ามีกฎการลินต์ (หรือวิธีแก้ปัญหา TypeScript) เพื่อบังคับใช้เรื่องนี้
ปัญหา:
const theObjectIdAsString = "6228ab5bedddb4fb156e1f73";
const objectId = new ObjectId(theObjectIdAsString)
const sameObjectId = new ObjectId(theObjectIdAsString)
// works as expected
objectId.equals(sameObjectId) // true
objectId.toHexString() === sameObjectId.toHexString() // true
// the oh-so-easy-to-make-mistake
objectId === sameObjectId // false
มีข้อเสนอแนะอะไรไหม?