question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with typescript types (http2 and https server)

See original GitHub issue

While trying to use restana with http2/https with typescript I’ve got some errors.

Here’s the code :

import http2 from "http2";
import pem from "pem";
import restana from 'restana'

pem.createCertificate({ days: 1, selfSigned: true }, async (err, keys) => {
  try {
    if (err) console.error(err);

    const service = await restana({
      server: http2.createSecureServer({
        cert: keys.certificate,
        key: keys.clientKey
      })
    });

    service.get("/", (req, res) => {
      res.send(req.url);
    });

    await service.start(8080);
  } catch (error) {
    console.error(error);
  }
});

Here’s the error :

Type 'Http2SecureServer' is missing the following properties from type 'Server': maxHeadersCount, timeout, headersTimeout, keepAliveTimeoutts(2739)

index.d.ts(116, 5): The expected type comes from property 'server' which is declared here on type 'Options<Protocol.HTTP>'

Here’s the code for the https :

import https from "https";
import pem from "pem";
import restana from "restana";

pem.createCertificate({ days: 1, selfSigned: true }, async (err, keys) => {
  try {
    if (err) console.error(err);

    const service = await restana({
      server: https.createServer({
        cert: keys.certificate,
        key: keys.clientKey
      })
    });

    service.get("/", (req, res) => {
      res.send(req.url);
    });

    await service.start(8080);
  } catch (error) {
    console.error(error);
  }
});

Here’s the error :

Argument of type '{ server: Server; }' is not assignable to parameter of type 'Options<Protocol.HTTP>'.
  Property 'errorHandler' is missing in type '{ server: Server; }' but required in type 'Options<Protocol.HTTP>'.ts(2345)

index.d.ts(124, 5): 'errorHandler' is declared here.

Here’s my tsconfig :

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "alwaysStrict": true,
    "baseUrl": "src",
    "esModuleInterop": true,
    "lib": ["dom", "esnext"],
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "dist",
    "pretty": true,
    "removeComments": true,
    "resolveJsonModule": true,
    "target": "esnext"
  },
  "exclude": ["node_modules", "tests/**/*.ts", "dist/**/*.ts"],
  "include": ["src/**/*.ts"]
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tomc974commented, May 21, 2019

@Julien-Broyard Hi! When calling restana you have to specify which protocol you are using. So if you change your function call to restana<restana.Protocol.HTTP2>, it should work.

1reaction
jkyberneeescommented, May 21, 2019

Hi @tomc974, can we kindly ask for your support here?

Best Regards.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript types not working for http2 #1840 - fastify ... - GitHub
and post an issue here that does not follow the instructions, your issue might be closed, locked, and assigned the missing discussion label....
Read more >
Typescript fastify http2 types not being passed - Stack Overflow
Using const opts: fastify.RouteShorthandOptions< http2.Http2SecureServer, http2.Http2ServerRequest, http2.Http2ServerResponse >. Works.
Read more >
Node.js TypeScript #15. Benefits of the HTTP/2 protocol
HTTP/2 solves this issue by allowing one connection to handle multiple requests at once – thanks to that even if one of them...
Read more >
HTTP/2 | Node.js v19.3.0 Documentation
The http2session.type property can be used to determine the mode in which an Http2Session is operating. On the server side, user code should...
Read more >
TypeScript - Fastify
There are two types of HTTP2 server types, insecure and secure. Both require specifying the http2 property as true in the options object....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found