Description
π Search Terms
export declare js emit
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
export declare let a: number;
a = 2;
π Actual behavior
When compiled to JS, will that code export a variable named a
? It depends!
- if compiling to ESM, no
- if compiling to CJS/AMD, yes
- if inside a
namespace
, yes
π Expected behavior
Compiling to ESM or to CJS/AMD should behave the same. Specifically, they should all have the ESM behavior (no a
exported), since declare
means "this statement is only to tell something to the type checker, it should not actually affect the emitted JS code".
Maybe referencing locally something declared as export declare
should be an error.
Additional information about the issue
Babel (babel/babel#17038), SWC (swc-project/swc#9821), and OXC (https://playground.oxc.rs/#eNo9TjFuwzAM/IrA2UNToIuKrp37gC60QgcGJFIg5TSB4b+XiuNo0R15d7wVEkRgLGQVEwW2sP5y8Ee3KtrCmVJGpZCpBYyBlzKSfu4SDF/h5HiDAQTiCrpw/+zODW8Qmy40QJ65QZwwmxNLUunY2L2Mkg/WFNkm0bIPtgEqqpH2xKrk6Eo/XoXtmeaKnv1QOH75d0tDvZAfBrL3t9MHuCLJmS7UKzopM8/TfJiTcFPJ31n+uvlKOop50f3Qtv0D8iJmOg==) already have the behavior I'm proposing.