Typescript compilation error when passing a restana `Service` to gateway constructor
Closed this issue · 2 comments
ydarma commented
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
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
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!