V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
zxCoder
V2EX  ›  问与答

使用 webstorm 写 nodejs(express.js 框架)遇到的问题

  •  
  •   zxCoder · Aug 10, 2021 · 1090 views
    This topic created in 1720 days ago, the information mentioned may be changed or developed.

    这两个都是文档里提到的中间件的写法,但是第一个四个参数的这个 ide 识别不了,第二个三个参数的这个,ide 可以识别,所以也有智能提示和代码高亮。这是为什么呢,是 webstorm 的 bug 还是我少了什么步骤

    app.use((err, req, res, next)=> {
        
    });
    
    app.use((req, res, next)=> {
        
    });
    
    2 replies    2021-08-10 18:20:20 +08:00
    initd
        1
    initd  
       Aug 10, 2021
    试试 app.use(function(err, req, res, next){})

    可能是 箭头函数 访问不到 作用域
    akaxiaok339
        2
    akaxiaok339  
       Aug 10, 2021
    因为 WebStorm 是根据一份 d.ts 来提示的,你不用 TS 指定类型,它就推断不出来
    https://stackoverflow.com/questions/50218878/typescript-express-error-function
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   849 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 21:21 · PVG 05:21 · LAX 14:21 · JFK 17:21
    ♥ Do have faith in what you're doing.