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 ts(2355)在尝试返回文档数组NodeJS、Mongoose、Typescript时_Node.js_Typescript_Mongoose - Fatal编程技术网

Node.js ts(2355)在尝试返回文档数组NodeJS、Mongoose、Typescript时

Node.js ts(2355)在尝试返回文档数组NodeJS、Mongoose、Typescript时,node.js,typescript,mongoose,Node.js,Typescript,Mongoose,我正在使用基于餐馆的MongoDB样本数据处理Typescript、Mongoose、NodeJS和Express 我试图创建简单的CRUD操作,目的是返回所有餐厅,然后返回特定的餐厅,最终过滤/排序等 请参见下面的功能: const fetchRestaurants = async (request: Request, response: Response): Promise<RestaurantInterface[]> => { try { const rest

我正在使用基于餐馆的MongoDB样本数据处理Typescript、Mongoose、NodeJS和Express

我试图创建简单的CRUD操作,目的是返回所有餐厅,然后返回特定的餐厅,最终过滤/排序等

请参见下面的功能:

const fetchRestaurants = async (request: Request, response: Response): Promise<RestaurantInterface[]> => {
  try {
    const restaurants: RestaurantInterface[] = await RestaurantModel.find();
    response.status(200).json({
      restaurants
    });
  } catch (error) {
    throw error;
  }
}

这是意料之中的,因为函数实际上返回void。当您编写
函数名():Promise
时,它意味着您应该
返回一些东西。而您只是调用Express的
json
方法。这是意料之中的事

// in another file
export interface RestaurantInterface {
  name: string,
  borough: string,
  cuisine: string,
  restaurant_id: string
  address: Address,
  grades: Grades[],
};