When I use this line on my Express server, it works well in TypeScript 1.x
mongoose.Promise = global.Promise;
( The usage of mongoose.Promise = global.Promise; is from the mongoose document )
After updating to TypeScript 2.x, it shows this error in the terminal, and won't let me start the server.
Left-hand side of assignment expression cannot be a constant or a read-only property.
How can I solve this? Thanks
This is because in
es6all module's variables are considered constants.In
TypeScript 2.0the bug (of not reporting this error) was fixed.Since
mongooseis still using thecommonjs-var mongoose = require("mongoose")- not thees6import syntax (which is used in the typings), you can suppress the error by assuming the module is of typeany.WORKAROUND: