I have a module written in TypeScript (demonstration source code is here: https://github.com/thejohnfreeman/bugs/tree/dece04bc4353bfc3f100c11fd38a4bb76cfcad67/parent) It has two source files:
// src/index.ts
export { String } from './types'
// src/types.d.ts
export type String = string
I can build parent as a JavaScript module:
yarn
npx tsc --project tsconfig.json --outDir out --module esnext
It compiles only the .ts file, and produces what I would expect,
a JavaScript module exporting an empty object:
// out/index.js
export {};
But if I change the .ts file to export everything from the .d.ts file,
like this:
// src/index.ts
export * from './types'
then I get an identical re-export statement in the output:
// out/index.js
export * from './types';
and because the .d.ts file produces no .js output, the import from
'./types' is dangling.
Is this a bug?
I expect TypeScript to recognize that everything re-exported from
'./types' is a type declaration, and for the export * from './types' line
to be compiled to nothing, just as if I had manually named every export from
'./types'.
I'm using TypeScript 4.2.4.