microsoft / TypeScript

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

Namespace elements cannot export without declaration #5220

Open falsandtru opened 9 years ago

falsandtru commented 9 years ago

es6 modules can export module elements without declaration.

import foo from 'foo';
export {foo}

Namespaces are not.

import foo from 'foo';
namespace NS {
  export {foo} // not support syntax
  export var foo = foo; // invalid

  var bar = foo;
  export var foo = bar; // too redundant
}

Namespaces should support non-declaration export.

related: https://github.com/Microsoft/TypeScript/issues/5175

RyanCavanaugh commented 9 years ago

What should the emit for this look like?

falsandtru commented 9 years ago

I want this syntax and emit compatible with es6 modules.

namespace NS {
  export {foo}
}
var NS;
(function (NS) {
    NS.foo = foo;
})(NS || (NS = {}));
falsandtru commented 9 years ago

use case

export default A

const Package = {
  Msg,
  Proxy: Proxy, // tslint bug. https://github.com/palantir/tslint/issues/684
  Tick: Tick
};

function A<T>() {
  return new ArchStream<T>();
}
namespace A {
  export const Msg = Package.Msg; // => export {Msg}
  export const Proxy = Package.Proxy; // => export {Proxy}
  export const Tick = Package.Tick; // => export {Tick}
}
jeffryang24 commented 5 years ago

I have the same problem like above:

export namespace HomePage {
  export namespace Action {
    export namespace ActionTypes {
      export const OPEN_API_REQUEST = '@@homePage/OPEN_API_REQUEST'; --> this is invalid. :(
    }
  }
}