BackendStack21 / fast-gateway

Fast-gateway is an easy to use Node.js API gateway framework built to handle large scale API traffic with great performance and scalability. Written with JavaScript, it is a framework for the masses!
MIT License
311 stars 35 forks source link

Typescript compilation error when passing a restana `Service` to gateway constructor #50

Closed ydarma closed 3 years ago

ydarma commented 3 years ago

Hi,

thank you for your work.

Describe the bug Cannot pass a restana Service object to the gateway in Typescript.

To Reproduce

import gateway from "fast-gateway";
import restana from "restana";

const server = gateway({
    server: restana(),
    routes: []
});

gives :

error TS2740: Type 'Service<Protocol.HTTP>' is missing the following properties from type 'Server': listen, address, getConnections, ref, and 25 more.

Expected behavior It should compile.

Solution in index.d.ts change line 50 :

server?: restana.Server<P>;

to

server?: restana.Service<P>;

This is coherent with line 18 of index.js :

const server = opts.server || restana(opts.restana)

and it works properly (for me).

ydarma commented 3 years ago

Hi,

This workaround works :

import gateway from "fast-gateway";
import restana from "restana";

const service = restana();
const server = gateway({
    server: Object.assign(service.getServer(), service),
    routes: []
});
jkyberneees commented 3 years ago

Hi @ydarma, thanks for reporting this issue. This is now fixed in v2.5.2

  interface Options<P extends restana.Protocol> {
    server?: Object | restana.Service<P> | Express.Application;
    ...
  }

Many thanks!