问题描述
我目前正在为nodejs微服务编写样板。技术堆栈还没有最终确定,但目前我正计划使用:
- KoaJS(带有@ koa / router)
- 打字稿
- TypeORM
- Nodemon
- Eslint(Airbnb打字稿配置)
我将如何验证端点中的输入?正文和查询被标记为任何值。如果我使用as <type>
,则会得到智能感知,但是参数仍然是错误的类型/未经验证。是否有任何软件包可以对此进行存档,或者通常采用什么方法处理?
const { skip = 0,take = 10 } = ctx.query as { skip: number,take: number };
// if skip is passed via query it prints: string
console.log(typeof skip)
// I could pass whatever I want in the body,after compilation the program obviously doesn't care
const body = ctx.request.body as SomeRequestModel;
我们也非常欢迎其他有关技术堆栈的反馈。
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)