'Keep getting the same error when building a simple schema/database file combination
Just building a simple database/schema files and keep getting this error when I tsc:
node_modules/mongodb/mongodb.d.ts:3314:5 - error TS2416: Property 'end' in type 'GridFSBucketWriteStream' is not assignable to the same property in base
type 'WritableStream'.
Type '{ (): void; (chunk: Buffer): void; (callback: Callback<void | GridFSFile>): void; (chunk: Buffer, callback: Callback<void | GridFSFile>): void; (chunk: Buffer, encoding: BufferEncoding): void; (chunk: Buffer, encoding: BufferEncoding, callback: Callback<...>): void; }' is not assignable to type '{ (cb?: () => void): this; (data: string | Uint8Array, cb?: () => void): this; (str: string, encoding?: BufferEncoding, cb?: () => void): this; }'.
3314 end(chunk: Buffer, encoding: BufferEncoding | undefined, callback: Callback<GridFSFile | void>): void;
I've searched everywhere but can't find a solution. This are my two files:
\\database.ts
import * as mongoose from 'mongoose'
var companyInfo =require('./companiesSchema/Company');
mongoose.connect("mongodb://localhost/FinancialReports")
saveToDB();
async function saveToDB() {
const company = await new companyInfo({companyName: "AMZN", companyStatments: "sdfsdgsdgsdgs"}) ;
await company.save()
console.log("Company Saved")
}
and
\\companiesSchema.ts
import * as mongoose from 'mongoose'
const companySchema = new mongoose.Schema({
companyName: String,
companyStatments: String
})
module.exports = mongoose.model('Company', companySchema);
Solution 1:[1]
It seems it is an error which happens only in @types/node v^17.0.6. Just change to a previous version (^16.11.7 worked for me) until the bug is fixed. More info here: https://github.com/mongodb/node-mongodb-native/pull/3088
Solution 2:[2]
I just faced this issue, updating mongoose to the latest version worked for me. At the time of writing this, the latest version is "mongoose": "^6.2.2".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | joaoM |
| Solution 2 | Tyler2P |
