microsoft / microsoft/TypeScript

No ways to do an alias of an exported type inside a namespace

Open
#40,771 2 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.