Skip to content

Allow module syntaxes for namespaces #46172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
karikera opened this issue Oct 2, 2021 · 2 comments
Closed

Allow module syntaxes for namespaces #46172

karikera opened this issue Oct 2, 2021 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@karikera
Copy link

karikera commented Oct 2, 2021

Suggestion

πŸ” Search Terms

export all from namespace
export default with namespace #24164
export from namespace

βœ… Viability Checklist

My suggestion meets these guidelines:

  • [v] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [v] This wouldn't change the runtime behavior of existing JavaScript code
  • [v] This could be implemented without emitting different JS based on the types of the expressions
  • [v] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • [v] This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

some namespace syntaxes are not compatible with module syntaxes.
It will be more flexible if they are supported.

πŸ“ƒ Motivating Example

  1. export * from namespace
    It's hard to export all identifiers in the namespace.
// sources

// module1.d.ts
export const a:number;
export const b:number;
export const c:number;
export ...

// index.d.ts
export * from "./module1";
declare let a:number;
export { a as foobar };
// bundled (by my program)

declare namespace module1 {
   export const a:number;
   export const b:number;
   export const c:number;
   export ...
}
// ***  suggestion ***
export * from module1;
declare let a:number;
export { a as foobar };
// current solution
import a_ = module1.a; // need to avoid the name dupplication
import b = module1.b;
import c = module1.c;
import ...
export { a_ as a, b, c, ... };
declare let a:number;
export { a as foobar };
  1. export default
    Support export { x as default } in namespace declarationsΒ #24164
// sources

// module1.d.ts
declare const a:number;
export default a;

// index.d.ts
import a from './module1';
// bundled (by my program)

declare namespace module1 {
  const a:number;
  // export default a; // suggesstion
  export { a as default }; // possible but not much meaning
  export { a as default_}; // bypass
}
// *** suggestion ***
import a from module1;
// current solution
import a = module1.default_; // TS does not allow 'default' even at this point. bypass it.
  1. import { ... } from namespace, export { ... } from namespace
// sources

// module1.d.ts
export const a:number;
export const b:number;
export const c:number;
export const d:number;

// index.d.ts
import { a as c, b as d } from './module1';
export { c, d } from './module1';
// bundled (by my program)
declare namespace module1 {
  export const a:number;
  export const b:number;
  export const c:number;
  export const d:number;
}

// *** suggestion **
import { a as c, b as d } from module1;
export { c, d } from module1;
// current solution
import c = module1.a;
import d = module1.b;
import c_ = module1.c; // need to avoid the name dupplication
import d_ = module1.d;
export { c_ as c, d_ as d };

πŸ’» Use Cases

I'm trying to bundle d.ts files programmatically.
and replacing modules with namespaces.
but it's a little hard to bundle them perfectly with the current syntaxes.

@andrewbranch andrewbranch added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Oct 4, 2021
@andrewbranch
Copy link
Member

Duplicate of #39865

@andrewbranch andrewbranch marked this as a duplicate of #39865 Oct 4, 2021
@andrewbranch andrewbranch added Duplicate An existing issue was already created and removed Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Oct 4, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants