timocov / dts-bundle-generator

A tool to generate a single bundle of dts with types tree-shaking
MIT License
762 stars 40 forks source link

Output strips `type` keyword from type import #320

Open egilsster opened 6 months ago

egilsster commented 6 months ago

Bug report

The generator seems to remove the type import keyword from the source, this can be troublesome for projects that have verbatimModuleSyntax enabled:

error TS1484: 'MyType' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

I'd be happy to take a stab at this issue if there isn't anything I can use to get this working. Both the project that's compiling this has the type, and the project using the type has verbatimModuleSyntax enabled.

Input code

import type { MyType } from "@my-internal-lib/some-type";

export type MyExportedType = {
  property: MyType;
};

declare global {
  // type augmentation
}

Expected output

import type { MyType } from "@my-internal-lib/some-type";

export type MyExportedType = {
  property: MyType;
};

declare global {
  // type augmentation
}

Actual output

import { MyType } from "@my-internal-lib/some-type";

export type MyExportedType = {
  property: MyType;
};

declare global {
  // type augmentation
}

Additional context

I am using the JS API and here are my options:

generateDtsBundle([
  {
    filePath: String(entry),
    outFile: output,
    output: { inlineDeclareGlobals: true },
  },
])
timocov commented 6 months ago

Duplicate of https://github.com/timocov/dts-bundle-generator/issues/290

timocov commented 6 months ago

Hm, actually, if it just about imports, it could be different issue and probably can be solved separately. I'll check in couple of days what we can do.

egilsster commented 6 months ago

Took a stab at this @timocov https://github.com/timocov/dts-bundle-generator/pull/321