microsoft / microsoft/TypeScript
No ways to do an alias of an exported type inside a namespace
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.9.7
Search Terms:
export type alias namespace
Code
With import type, in case of long namespaces encapsulation, there's no way to do an alias of the namespaces.
We are forced to alias the final types / interfaces
file types.ts
type A = {}
type B = {}
type C = {}
export type {
A,
B,
C
};
file namespace1.ts
import type * as namespace1 from 'types';
export type {namespace1}
file namespace2.ts
import type * as namespace2 from 'namespace1';
export type {namespace2}
file finalUsage.ts
import type {namespace2} from 'namespace2';
type A = namespace2.namespace1.A; // this is working
namespace aliasNamespaces2 {
export import namespace1 = namespace2.namespace1; // fails with message 'An import alias cannot reference a declaration that was imported using 'import type'. '
}
Expected behavior:
we need a way to make a shortcut of namespaces2.namespace1
Actual behavior:
Cannot do it: we are forced to aliasthe final types namespaces2.namespace1.A
Playground Link:
Related Issues:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the behavior in the example files types.ts, namespace1.ts, namespace2.ts, and finalUsage.ts with the reported TypeScript 3.9.7 setup. Trace the handling of import type aliases and namespace references, then define and test a supported way to shorten namespace2.namespace1 without the current import-type error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100