Force export as a type export to replace a namespace usage.
- Dominant language
- Rust
- Stars
- 1.3k
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I almost port ChromeDevToolsProtocol project to deno, I'm facing an last error.
## Original version
My ChromeDevToolsProtocol api use to contains a big protocol.d.ts file like this:
```ts
export namespace Protocol {
export namespace Accessibility {
export interface ....
}
}
```
exported in `mod.ts` with:
```ts
export { Protocol } from "./types/protocol.d.ts";
```
[full file](https://github.com/UrielCh/ChromeDevToolsProtocol/blob/18c52936f1242a821dd833d2030f5852686e2869/chrome-remote-interface/types/protocol.d.ts)
as mention in [Deno FAQS](https://deno.land/manual/typescript/faqs)
> - Only declare namespace is supported. Runtime namespace is legacy TypeScript syntax that is not supported.
## Fixed version
So to clean that, I replace all those namespace by modules
in protocol.d.ts :
```ts
export * as Accessibility from './accessibility.d.ts'
```
exported in `mod.ts` with:
```ts
export * as Protocol from "./types/protocol.d.ts";
```
[full version](https://github.com/UrielCh/ChromeDevToolsProtocol/blob/fccd48db64ec70a5001753c232166d369733e841/chrome-remote-interface/types/protocol.d.ts)
With that change my deno code works fine.
But once converted to nodeJS with dnt, this export is generated as a code export, event if it only contains interfaces. (I also replace interface by type) so it only contains type.
The dnt conversion end with an error:
```
Error: Cannot find module './types/protocol'
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
}
```
The line causing the error in the generate node code is:
```
exports.Protocol = __importStar(require("./types/protocol"));
```
yep, the is no code for protocol, it's only a definition file.
To fix that I should replace:
`export * as Protocol from "./types/protocol.d.ts";`
by something like that:
`export type * as Protocol from "./types/protocol.d.ts";`
but this syntax is not valid in Typescript.
What did I do wrong ? how can I force this `export * as` to be a type.
Thx for your time, deno is great.
Contributor guide
Research direction
Reproduce the dnt conversion using the linked ChromeDevToolsProtocol example, starting with mod.ts and types/protocol.d.ts, then inspect the generated entry point around exports.Protocol. Compare handling of export * as for a .d.ts-only module with runtime modules; done means no require("./types/protocol") is emitted while the generated package still exposes the protocol types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100