When I convert a string
to ObjectId
, I use
import * as mongoose from 'mongoose';
const objId = mongoose.Types.ObjectId(strId);
It works well in TypeScript 1.x, after updating to TypeScript 2.x, I got the error:
error TS2348: Value of type 'typeof ObjectID' is not callable. Did you mean to include 'new'?
How can I solve it? Thanks
new
? Should be as simple as:const objId = new mongoose.Types.ObjectId(strId);
– Nitzan Tomer