Typescript + Express : Type 'typeof e' has no compatible call signatures

后端 未结 1 2031
逝去的感伤
逝去的感伤 2021-02-19 04:53

I\'m trying to build an application using typescript , express . but i\'m getting this error : Cannot invoke an expression whose type lacks a call signature. Type \'typeo

相关标签:
1条回答
  • 2021-02-19 05:51

    You need to import the default export from express instead of the namespace (which is an object with all named exports).

    In your app.ts this should be all you need:

    // Change these
    import express from "express";
    import bodyParser from "body-parser";
    
    

    The difference is:

    // Namespace import
    import * as express from "express";
    
    const app = express.default();
    
    // Default import
    import express from "express";
    
    const app = express();
    
    
    0 讨论(0)
提交回复
热议问题