Type is not assignable to type 'OptionalId<T>'

Any ideas?

I’m trying to write a Typescript generic using the Nodejs driver v4.1.0. I was using the DefinitelyTyped types so I’m refactoring to bring everything up to speed.

I have 3 type interfaces that extend the interface ICMDR. ICMDR is the one with _id.

Attempting to do the following:

const post = async <T extends ICMDR>(res: NextApiResponse, db: Db, cmdr: T) => {
  delete cmdr._id;
  await db.collection<T>('cmdrs').insertOne(cmdr);

ESLint is flagging it with

Argument of type ‘T’ is not assignable to parameter of type ‘OptionalId’.
Type ‘ICMDR’ is not assignable to type ‘OptionalId’.ts(2345)

Here’s the ICMDR:

export interface ICMDR {

  _id?: ObjectId; //from BSON

  cmdrName: string;

  discordName: string;

  discordJoinDate: Date;

  platform: Platform;

  rank: Rank;

  inaraLink?: string;

  region: Region;

  notes?: string;

  email?: string;

  isDeleted?: boolean;


I guess it blocked my code because it thought it was a link:

delete cmdr._id; is so mongo won’t refuse on the basis of the _id being present already.