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

Typescript error with createMidleware function #499

Closed
natoehv opened this issue Oct 22, 2020 · 7 comments
Closed

Typescript error with createMidleware function #499

natoehv opened this issue Oct 22, 2020 · 7 comments

Comments

@natoehv
Copy link
Contributor

natoehv commented Oct 22, 2020

Hi everybody!

I started to work with the new typescript integration (I'm using Express), and I got an error with the createMidleware function
image
theapp variable is defined as Express.Application,

TS Error:
Type 'Application' is missing the following properties from type 'TApp': setTimeout, maxHeadersCount, timeout, headersTimeout, and 9 more.ts(2740)

Should I change the typing of the application?

thanks you!

@tdeekens
Copy link
Owner

Thanks for opening.

TApp just extends Server from http. What are you passing in? Otherwise you could also get away with casting it. https://github.com/tdeekens/promster/blob/main/packages/express/modules/middleware/middleware.ts#L16

@natoehv
Copy link
Contributor Author

natoehv commented Oct 22, 2020

I'm using an express application:

const applyMiddleware = ({ app, path, regexPath, rewritePath }: PrometheusConfig) => {
  app.use(createMiddleware({
    app,
    options: {
      normalizePath: (originalpath) => {
        if (regexPath && !!regexPath.exec(originalpath)) {
          return rewritePath || 'customPath';
        }
        return originalpath;
      },
    },
  }));
...
}
export declare interface PrometheusConfig {
  app: express.Application;
  path: string;
  regexPath?: RegExp;
  rewritePath?: string;
}

and I use it:

const app = express();
const appProm = applyMiddleware({ app, path: promPath });

PD: I can't cast to TApp, because it doesn't export :(

@tdeekens
Copy link
Owner

Would it help you if we'd export it? Maybe try it with a fork. If it works I'd be happy to see a PR.

@natoehv
Copy link
Contributor Author

natoehv commented Oct 23, 2020

exporting the class did not work, but if a change in the type of TApp, what do you think?

#500

@tdeekens
Copy link
Owner

Awesome. Thanks for contributing.

@tdeekens
Copy link
Owner

Will be published from CI.

@natoehv
Copy link
Contributor Author

natoehv commented Oct 27, 2020

thank you @tdeekens 👍 now is working fine 🥇

@natoehv natoehv closed this as completed Oct 27, 2020
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

2 participants