大佬教程收集整理的这篇文章主要介绍了node.js – Typescript 2.2 Express req,res隐式任意,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用TypeScript 2.2并表达4.x并且我通过npm安装了类型:
npm install –save-dev @ types / express
import * as express from "express" const app: express.Application = express() app.get("/Hello",(req,res) => { res.send("world") })
这给了我:
src/app.ts(33,22): error TS7006: Parameter 'req' implicitly has an 'any' type. src/app.ts(33,27): error TS7006: Parameter 'res' implicitly has an 'any' type.
我试图避免为所有请求处理程序执行此操作:
(req: express.request,res: express.ResponsE) => {}
在我看来它应该能够推断出那些.我错了吗?这不可能吗?
tsconfig.json:
{ "compilerOptions": { "target": "es6","module": "commonjs","noImplicitAny": true,"sourceMap": true,"outDir": "dist","typeRoots": ["src/types","node_modules/@types"] },"include": [ "src/**/*.ts" ] }
谢谢!
interface requestHandler { (req: request,res: Response,next: NextFunction): any; } interface ErrorrequestHandler { (err: any,req: request,next: NextFunction): any; } type PathParams = String | RegExp | (String | RegExp)[]; type requestHandlerParams = requestHandler | ErrorrequestHandler | (requestHandler | ErrorrequestHandler)[]; interface IRouterMatcher<T> { (path: PathParams,...handlers: requestHandler[]): T; (path: PathParams,...handlers: requestHandlerParams[]): T; }
以上是大佬教程为你收集整理的node.js – Typescript 2.2 Express req,res隐式任意全部内容,希望文章能够帮你解决node.js – Typescript 2.2 Express req,res隐式任意所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。