构建简单的 schema/database 文件组合时不断出现相同的错误
Keep getting the same error when building a simple schema/database file combination
只是构建一个简单的 database/schema 文件,当我 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;
我到处搜索,但找不到解决方案。
这是我的两个文件:
\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")
}
和
\companiesSchema.ts
import * as mongoose from 'mongoose'
const companySchema = new mongoose.Schema({
companyName: String,
companyStatments: String
})
module.exports = mongoose.model('Company', companySchema);
好像是@types/node v^17.0.6 才出现的错误。只需更改为以前的版本(^16.11.7 对我有用)直到错误被修复。
更多信息在这里:https://github.com/mongodb/node-mongodb-native/pull/3088
我刚遇到这个问题,将猫鼬更新到最新版本对我有用。在撰写本文时,最新版本是 "mongoose": "^6.2.2"
.
只是构建一个简单的 database/schema 文件,当我 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;
我到处搜索,但找不到解决方案。 这是我的两个文件:
\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")
}
和
\companiesSchema.ts
import * as mongoose from 'mongoose'
const companySchema = new mongoose.Schema({
companyName: String,
companyStatments: String
})
module.exports = mongoose.model('Company', companySchema);
好像是@types/node v^17.0.6 才出现的错误。只需更改为以前的版本(^16.11.7 对我有用)直到错误被修复。 更多信息在这里:https://github.com/mongodb/node-mongodb-native/pull/3088
我刚遇到这个问题,将猫鼬更新到最新版本对我有用。在撰写本文时,最新版本是 "mongoose": "^6.2.2"
.