【发布时间】:2020-08-01 22:42:34
【问题描述】:
在 npm i 之后,如果我尝试将查询参数传递给需要字符串的函数,则会出现以下错误:
'string | 类型的参数查询 | (string | Query)[]' 不能分配给“string”类型的参数。
类型 'Query' 不可分配给类型 'string'.ts(2345)
import express from "express";
async function getProductsImagesByShopEvent(req: express.Request, res: express.Response,
next: express.NextFunction) {
try {
const params = req.query;
if (!params || !params.shopEventId)
throw new CustomError("params are missing in /business/getProductsImagesByShopEvent", 400, "params are missing");
const shopEvent = new ShopEvent();
const events = await shopEvent.getProductsImagesByShopEvent(params.shopEventId);
res.json(events);
}
catch (error) {
next(error);
}
}
async getProductsImagesByShopEvent(shopEventId: string) {
}
错误在 params.shopEventId.. 如果我添加: const params = (req.query as any);它有效
【问题讨论】:
标签: node.js typescript express