Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import "type" keyword for compatibility with TypeScript verbatimModuleSyntax #678

Open
turadg opened this issue Oct 22, 2024 · 0 comments
Open
Assignees

Comments

@turadg
Copy link
Contributor

turadg commented Oct 22, 2024

Problem

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

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,

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:

  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);
@Zetazzz Zetazzz assigned NorOldBurden and Zetazzz and unassigned Zetazzz Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants