@types/express
and @types/express-serve-static-core
package and had problems.Definitions by:
in index.d.ts
) so they can respond.Code:
import * as express from "express";
import { Request, Response } from "express";
import * as bodyParser from "body-parser";
import * as api from "./routes/api";
namespace my_api {
let app = express();
let port: number = process.env.port || 3000;
app.use(bodyParser.json());
app.use('/api', api);
app.get('/', (req: Request, res: Response) => {
res.send("Hello world");
});
app.listen(port, () => console.log(`Express app listening on port ${port}`);
}
When building:
ERROR in /path/to/server.ts (25,11): Argument of type '"/api"' is not assignable to parameter of type 'RequestHandlerParams'.
Related:
expressjs/express#3263
hi @natejgardner
I encountered this error too and spent way too much time figuring this out. I tried fixing types definition by writing own d.ts. files but I failed. Then I came across this expressjs: typescript: Argument of type 'typeof
I see a lot of problems with TypeScript types and Expressjs and maybe this issue is serious but importing without using * seems to solve problem at least with calling overloaded use function.
@natejgardner your problem is into the Api Router:
you can try a solution like this (into "./routes/api" file):
import { Router } from "express";
const router: Router = Router();
router.get("/", getInfo);
// ...other routes...
export = router;
It's work for me....enjoy :)
Is this fixed ?
Most helpful comment
hi @natejgardner' is not assignable to parameter of type 'RequestHandlerParams'
I encountered this error too and spent way too much time figuring this out. I tried fixing types definition by writing own d.ts. files but I failed. Then I came across this expressjs: typescript: Argument of type 'typeof
I see a lot of problems with TypeScript types and Expressjs and maybe this issue is serious but importing without using * seems to solve problem at least with calling overloaded use function.