1

I have these files:

  • foo.ts
  • foo.d.ts (hand-authored)
  • bar.ts

I want to use TypeScript to generate the following output

  • foo.js
  • foo.d.ts (same as my hand-authored one)
  • bar.ts
  • bar.d.ts

TypeScript ignores my hand-authored foo.d.ts in this case and just generates a .d.ts from foo.ts. How can I get TS to pass through hand-authored .d.ts files when there is a corresponding .ts?

Max Heiber
  • 14,346
  • 12
  • 59
  • 97
  • Why would you have definition file for ts file? – Roberto Zvjerković Jun 29 '19 at 14:53
  • Good question. Someone asked for this feature, and I should probably go back and ask why they want it. But I'm still curious if it's possible. – Max Heiber Jun 30 '19 at 10:50
  • I have no idea if it's possible, it doesn't really make sense. You use definition files to define JavaScript file types. If you have a TypeScript file, just define types there. What would happen with compiler if `.ts` and `.d.ts` files have conflicting type definitions? `export function Foo(): string` and `export function Foo(): number`. Which one is right? I guess compiler just ignores `.d.ts` file when there is `.ts`file there. – Roberto Zvjerković Jun 30 '19 at 10:55
  • Yes, the compiler seems to ignore .d.ts file when there is a .ts – Max Heiber Jun 30 '19 at 12:41
  • I suspect the answer is: There aren't many cases for hand-authoring a .d.ts when there is a corresponding for .ts. Unlike header files in C/C++, TS has `export`. So TS authors have the options to keep types private, or export wider or narrower versions of a type or aggregate types from many other files and expose them together. – Max Heiber Jul 01 '19 at 10:15

0 Answers0