Problem with typescript types (http2 and https server)
See original GitHub issueWhile 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:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Julien-Broyard Hi! When calling
restana
you have to specify which protocol you are using. So if you change your function call torestana<restana.Protocol.HTTP2>
, it should work.Hi @tomc974, can we kindly ask for your support here?
Best Regards.