microsoft / microsoft/TypeScript

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

Đang mở
#40,771 2 bình luận 12 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Awaiting More Feedback Suggestion
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

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:

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện hành vi trong các tệp ví dụ types.ts, namespace1.ts, namespace2.ts và finalUsage.ts với thiết lập TypeScript 3.9.7 được báo cáo. Theo dõi cách xử lý import type aliases và namespace references, sau đó xác định và kiểm thử một cách được hỗ trợ để rút gọn namespace2.namespace1 mà không gặp import-type error hiện tại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
typescript
Lĩnh vực
compilers
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
30/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.