Skip to content

Fix custom APIs types #2421

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

Closed
infomiho opened this issue Dec 17, 2024 · 3 comments · Fixed by #2569
Closed

Fix custom APIs types #2421

infomiho opened this issue Dec 17, 2024 · 3 comments · Fixed by #2569
Assignees
Labels
bug Something isn't working

Comments

@infomiho
Copy link
Contributor

I was building a custom API endpoint:

import { GetStaticResource } from "wasp/server/api";

export const getStaticResource: GetStaticResource = async (
  req,
  res,
  context
) => {
  return res.json({ message: "Hello from getStaticResource" });
};

When I type res. I don't get any autocomplete. When I clicked through the types of Api I found this:
Image

It complains we are missing @types/express.

And when I changed express to express-serve-static-core, the types auto-complete worked.

Proposed implementation

We should either swap out express for express-serve-static-core when we are after Express types or investigate if there is a better way (a newer way) to get the Express types since Express development started again. (Maybe the solution will be upgrading to Express v5 in the end?)

@infomiho infomiho added the bug Something isn't working label Dec 17, 2024
@cprecioso cprecioso self-assigned this Mar 19, 2025
@cprecioso
Copy link
Member

We should either swap out express for express-serve-static-core when we are after Express types or investigate if there is a better way [...]

Why not just install @types/express if we're using the express package?

@sodic
Copy link
Contributor

sodic commented Apr 16, 2025

What about express-static-core? I see that's still in the dependencies array. Should it be?

Also, it seems we left @types/express in the ServerGenerator. We should probably remove it.

@cprecioso
Copy link
Member

We're still using both:

import { type Request, type Response } from 'express'
import {
type ParamsDictionary as ExpressParams,
type Query as ExpressQuery,
} from 'express-serve-static-core'

@types/express-serve-static-core's Request and Response are not exactly the ones from @types/express, and @types/express doesn't export Query or ParamsDictionary. That's why I kept both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants