question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a way to alias namespaces

See original GitHub issue

TypeScript should have a way to embed (type) namespaces. In the following case, assigned (embeded) namespace NS.A should have a C type.

TypeScript Version: master

Code

namespace NS_A {
  export class C {
  }
}
namespace NS {
  export var A = NS_A;
  export type A = NS_A;
}
var C = NS.A.C;
type C = NS.A.C;

Expected behavior:

$ node built/local/tsc.js --lib es6 -m commonjs --noEmit index.ts

Actual behavior:

$ node built/local/tsc.js --lib es6 -m commonjs --noEmit index.ts
index.ts(7,19): error TS2304: Cannot find name 'NS_A'.
index.ts(10,13): error TS2305: Module 'NS' has no exported member 'A'.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:25
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

24reactions
RyanCavanaughcommented, Aug 6, 2016

I’ve been thinking about this as well. We have var / const to alias a value, and type to alias a type, but no equivalent for namespace. We could even consider

namespace ns = foo;

for establishing namespace aliases.

16reactions
pgherveoucommented, Jun 24, 2020

stumbled upon this issue, it looks like this feature is supported now see doc here https://www.typescriptlang.org/docs/handbook/namespaces.html#aliases @falsandtru if that answer your question you might want to close this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Namespace aliases - cppreference.com
Namespace aliases allow the programmer to define an alternate name for a namespace. They are commonly used as a convenient shortcut for long...
Read more >
In C++, what is a "namespace alias"? - Stack Overflow
A namespace alias is a convenient way of referring to a long namespace name by a different, shorter name. As an example, say...
Read more >
How to use :: Namespace Alias Qualifier in C# - GeeksforGeeks
Namespace Alias Qualifier(::) makes the use of alias name in place of longer namespace and it provides a way to avoid ambiguous definitions ......
Read more >
Creating an alias for a nested namespace (C++ only) - IBM
Namespace definitions hold declarations. Since a namespace definition is a declaration itself, namespace definitions can be nested. An alias can also be applied ......
Read more >
One of C++ most underrated features: Namespace aliases
In case you didn't know (which is likely): A namespace alias is just that - an alias for a namespace. Just like a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found