Exporting TypeScript types
See original GitHub issueWhilst migrating the main helmet
package over to TypeScript, I discovered an issue to do with exporting types:
Property 'dnsPrefetchControl' of exported interface has or is using name 'DnsPrefetchControlOptions' from private module '"./node_modules/dns-prefetch-control/dist/index"'.
In this example, I believe the DnsPrefetchControlOptions
type needs to be exported in the main module definition. However, because we are using CJS exports, we cannot simply prefix the type definition with export
(as there can only be a single export). Instead, the suggested way is to use namespaces:
/* eslint-disable @typescript-eslint/no-namespace */
namespace dnsPrefetchControl {
export interface DnsPrefetchControlOptions {
/* ... */
}
}
// eslint-disable-next-line no-redeclare
function dnsPrefetchControl (options: dnsPrefetchControl.DnsPrefetchControlOptions = {}) {
/* ... */
}
In the interest of preserving CJS exports, does this seem like a reasonable way for now? In the future, we can make a breaking change to use ES modules everywhere which would make things a lot nicer, but this change would at least make it possible to migrate this module to TypeScript. 👍
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Documentation - Modules - TypeScript
The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or...
Read more >How to export a Type in TypeScript | bobbyhadz
Use a named export to export a type in TypeScript, e.g. export type Person = {} . The exported type can be imported...
Read more >What is `export type` in Typescript? - javascript - Stack Overflow
This is a type alias - it's used to give another name to a type. In your example, feline will be the type...
Read more >export type * from 'somewhere' #48508 - GitHub
Suggestion Search Terms typescript export type star ✓ Viability Checklist My suggestion meets these guidelines: This wouldn't be a ...
Read more >Leveraging Type-Only imports and exports with TypeScript 3.8
TypeScript Type -Only imports/exports are a useful addition to the language, allowing us to have more fine-grained control over what TypeScript does for...
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
TypeScript types were added to Helmet in version 4, which you can install with
npm install helmet@4
. Closing this issue because I believe this is resolved, but feel free to comment or open a new issue.Ah, okay, I think that all makes sense to me now.
Given that…
helmet@4
is going to support all the way down to Node 8I think we should use
export =
like we do now. If that means we have to use deprecated TypeScript namespaces, that’s okay with me. It’s not ideal, but based on the givens above (which we could certainly debate), I think that’s the only option.Does that sound right?