Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@types/express, @types/express-serve-static-core -- Basic server fails. 'Argument of type '"/api"' is not assignable to parameter of type 'RequestHandlerParams'. #18647

Closed
2 of 3 tasks
natejgardner opened this issue Aug 4, 2017 · 5 comments

Comments

@natejgardner
Copy link

natejgardner commented Aug 4, 2017

  • [x ] I tried using the @types/express and @types/express-serve-static-core package and had problems.
  • I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • Mention the authors (see 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

@natejgardner natejgardner changed the title @types/express -- Basic server fails. 'Argument of type '"/api"' is not assignable to parameter of type 'RequestHandlerParams'. @types/express, @types/express-serve-static-core -- Basic server fails. 'Argument of type '"/api"' is not assignable to parameter of type 'RequestHandlerParams'. Aug 4, 2017
@develucas
Copy link

develucas commented Aug 16, 2017

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 <express.Router>' is not assignable to parameter of type 'RequestHandlerParams'
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.

@carmas123
Copy link

@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 :)

@danielpza
Copy link
Contributor

Is this fixed ?

@orta
Copy link
Collaborator

orta commented Jun 7, 2021

Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the @types modules in DefinitelyTyped.

To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the definitely-typed channel.

@orta orta closed this as completed Jun 7, 2021
@orta
Copy link
Collaborator

orta commented Jun 7, 2021

Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the @types modules in DefinitelyTyped.

To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the definitely-typed channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants