hyperweb-io / hyperweb-io/telescope

import "type" keyword for compatibility with TypeScript verbatimModuleSyntax

Open
#678 0 comments 0 reactions 1 assignee Assigned to @NorOldBurden View on GitHub
Dominant language
TypeScript
Stars
154
Forks
53
PR merge metrics
No merged PRs in 30d

Description

# Problem
In the generated code, the import statements don't distinguish between runtime values and buildtime types. E.g.

```ts
import { Lien, LienSDKType } from './lien.js';
import { JsonSafe } from '../../json-safe.js';
```

This causes errors with TypeScript `verbatimModuleSyntax` and libraries like https://bloomberg.github.io/ts-blank-space/ that require it.

# Proposed solution

In the output precede type imports with `type`. So for the example above,
```ts
import { Lien, type LienSDKType } from './lien.js';
import { BinaryReader, BinaryWriter } from '../../binary.js';
import { type JsonSafe } from '../../json-safe.js';
```

# Fallback

This snippet can be used with `child_process` `exec` to clean up the files after they're generated:
```js
const command = `
find ${fullPath} -type f -exec sed -i '' \
-e 's/import { JsonSafe/import {type JsonSafe/g' \
-e 's/\\([{,]\\) \\([[:alnum:]_]*SDKType\\)/\\1 type \\2/g' {} +
`;
exec(command);
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.