Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 猫鼬;。包括';-类型为'的参数;ObjectId';不可分配给类型为';{type:ObjectId;必需:true;}';_Node.js_Typescript_Mongoose - Fatal编程技术网

Node.js 猫鼬;。包括';-类型为'的参数;ObjectId';不可分配给类型为';{type:ObjectId;必需:true;}';

Node.js 猫鼬;。包括';-类型为'的参数;ObjectId';不可分配给类型为';{type:ObjectId;必需:true;}';,node.js,typescript,mongoose,Node.js,Typescript,Mongoose,我正在将我的JS node/express&mongoose服务器转换为Typescript,我对mongoose的数组包含方法和Typescript有一个问题: Argument of type 'ObjectId' is not assignable to parameter of type '{ type: ObjectId; required: true; }'. Type 'ObjectId' is missing the following properties from typ

我正在将我的JS node/express&mongoose服务器转换为Typescript,我对mongoose的数组包含方法和Typescript有一个问题:

Argument of type 'ObjectId' is not assignable to parameter of type '{ type: ObjectId; required: true; }'.
  Type 'ObjectId' is missing the following properties from type '{ type: ObjectId; required: true; }': type, required

78     if (!building.actors.includes(mongoose.Types.ObjectId(userID)))
导致此问题的行如下所示:

const transformedUserID = mongoose.Types.ObjectId(userID)
if (transformedUserID && !building.actors.includes(transformedUserID)) {
   ...
错误表明缺少必需的属性,因此我认为可能是涉及userID可能为null的问题,因此我尝试了此方法,但没有成功:

transformedUserID || mongoose.Types.ObjectId()
我是Typescript新手,所以我不太清楚为什么会发生这种情况,它在纯JS中工作得非常好。任何帮助都将不胜感激


谢谢

解决了问题所在-我在建筑模型的typescript界面中使用了
mongoose.Schema.Types.ObjectId
,而不是
mongoose.Types.ObjectId