TypeScript and export HelmetOptions
See original GitHub issueHi,
We have a function that looks similar to:
/**
* Get a list of default Helmet options we use for e.g. our
* http and websocket (socket.io) routes.
*
* @returns {HelmetOptions} The options to use with Helmet
*/
function getHelmetOptions() {
return {
hsts: {
maxAge: 31536000,
},
expectCt: false,
};
}
The reason is we use these options both for basic Express apps but also for socket.io routes. But there is no way to import the HelmetOptions
interface like import {HelmetOptions} from "helmet";
Could you, in addition to the default export, also export the named export HelmetOptions
for usage scenarios like above?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Exporting TypeScript types · Issue #209 · helmetjs/helmet
Whilst migrating the main helmet package over to TypeScript, I discovered an issue to do with exporting types: Property 'dnsPrefetchControl' ...
Read more >TypeScript: Documentation - Modules
Exporting a declaration. Any declaration (such as a variable, function, class, type alias, or interface) can be exported by adding the export keyword ......
Read more >Upgrading Helmet to v4.5.0 and needing equivalent type to ...
Rework your code a bit. You could update the Options interface to take all of Helmet's options: import helmet from 'helmet'; export ......
Read more >Modules & CJS interop - Learn TypeScript w/ Mike North
ES Module imports and exports. First, let's get the conventional stuff out of the way: TypeScript does exactly what you're used to seeing...
Read more >Announcing TypeScript 4.7 Beta
Today we are excited to announce the beta release of TypeScript 4.7! ... import / export statements (and top-level await in nodenext )...
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 FreeTop 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
Top GitHub Comments
I think only attempt 3 should succeed, so things are working as expected. (I think!)
Attempt 1 is trying to import
HelmetOptions
which is a TypeScript type. You can’t import TypeScript types from plain JavaScript, so this shouldn’t work.Attempt 2 imports Helmet’s default export, not the Helmet namespace.
HelmetOptions
is not part of the default export, so this shouldn’t work either. It seems that Express works differently.Attempt 3 imports Helmet as a namespace.
HelmetOptions
is part of that namespace, so it should work.Hope this helps.
@EvanHahn I tested a few things with this and have some findings. My knowledge of TypeScript is not good enough to deduct if there is something that can be done or not, but wanted to share. Note we are not using TypeScript directly in our code, but more the TypeScript in JSDoc (via a jsconfig.json) which is how some editors support TypeScript in JavaScript projects, such as VS Code.
Attempt 1 (failed)
Attempt 2 (failed)
Attempt 3 (passed)
Alternate example with the express module (passes)
As you can see for some reason at least the Express example works, which mimics attempt 2.