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

Express middleware skipping by request generates a TS error #1054

Closed
YahiaElTai opened this issue May 3, 2023 · 0 comments · Fixed by #1096
Closed

Express middleware skipping by request generates a TS error #1054

YahiaElTai opened this issue May 3, 2023 · 0 comments · Fixed by #1096

Comments

@YahiaElTai
Copy link

YahiaElTai commented May 3, 2023

Describe the bug
skip in TMiddlewareOptions requires 2 generic Q and S that can't be extended with Request and Response from express.

I might be using it wrong, a helpful usage example would be greatly appreciated 🙏

To Reproduce
Steps to reproduce the behavior:

  1. Given
import type { Request } from 'express';
import { createMiddleware as createPrometheusMiddleware } from '@promster/express';

app.use(
  createPrometheusMiddleware({
    app,
    options: {
      skip: <Q extends Request>(req: Q) =>
        req.url.includes('products') || req.url.includes('carts'),
    },
  })
);
  1. Then I receive a TS error
Types of parameters 'req' and 'request' are incompatible.
    Type 'Q' is not assignable to type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'


This type parameter might need an `extends e.Request<ParamsDictionary, any, any, QueryString.ParsedQs, Record<string, any>>` constraint.

Expected behavior
I expect the skip method to work without TS error or even better to have a different signature for example like this without the use of generics

app.use(
  createPrometheusMiddleware({
    app,
    options: {
      skip: (req: Request) =>
        req.url.includes('products') || req.url.includes('carts'),
    },
  })
);

Additional context
Versions installed

    "prom-client": "^14.2.0",
    "@promster/express": "^7.0.6",
    "@promster/server": "^7.0.8",
    "@promster/types": "^3.2.5",

One an unrelated note, it would be really nice if the express middleware exports the types as well so we don't have to install @promster/types to get typing for TMiddlewareOptions 😅

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

Successfully merging a pull request may close this issue.

1 participant