microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.35k stars 12.54k forks source link

Declaration file emitted with esModuleInterop can't be consumed without it #28009

Open ghost opened 6 years ago

ghost commented 6 years ago

TypeScript Version: 3.2.0-dev.20181019

Search Terms:

Code

import abs from "abs"; // using @types/abs which uses `export =`
export const x: typeof abs = <any>null;

Expected behavior:

Output .d.ts is:

import abs = require("abs");
export declare const x: typeof abs;

Actual behavior:

import abs from "abs";
export declare const x: typeof abs;

Discovered in quill on DefinitelyTyped, which imports from quill-delta, which is written in TypeScript with esModuleInterop.

weswigham commented 6 years ago

This is entirely because we strive not to rewrite people's code, and so during declaration emit, we preserve their interop-requiring-import-style. I'm... not sure if it's a bug or just unfortunate? I know prior to the new declaration emitter it'd be in the "unfortunate" category, since we also had the same problem with noImplicitAny; but the new declaration emitter solved all those problems by annotating any's on anything missing them. So in that same vein, I can conceive us changing our emit to automatically fix this up, too.

amitdahan commented 5 years ago

IMO - this is the (implied) expected behavior of auto-generated declaration files. You would think your generated declarations would be "universally" consumable, but as of now - they're unfortunately not :( I'd be very happy to see this fixed (assuming I can call it a bug).

aleclarson commented 4 years ago

Bump. It would be great if this was fixed. 😄