microsoft / microsoft/TypeScript

Re-export module namespace as global

Đang mở
#14,051 19 bình luận 19 reaction 0 người được giao Xem trên GitHub

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

In Discussion 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ả

We're attempting to migrate users within Google to new @types typings, which move most typings into modules, and having a ton of trouble. The basic problem is that a module (e.g. CodeMirror) used to declare a global complex interface:

declare function CodeMirror(...);
declare namespace CodeMirror { ... }

and now they are modules:

export = CodeMirror;

and other typings refer to them as modules (so we can't just undo that export statement) but we also have tons of older user code that doesn't refer to them as modules. Ideally we'd be able to make it work both ways while we migrate users incrementally.

I appreciate that you don't want the language to make this convenient, but I'm having difficulty finding any way to make it work temporarily while we migrate.

Some things I tried:

  1. Aliasing the module into the global namespace
declare global {
  import CodeMirror = require('codemirror');
}

(and other variants) fails with "Imports are not permitted in module augmentations.".

  1. Making the module global first, then aliasing it into a module namespace.
    If you wrap the file contents with a "declare global {", then I couldn't figure out a way to repackage that global as a module again. The export = CodeMirror; fails with "Cannot find name 'CodeMirror'." despite the global CodeMirror being declared in the same file.

Do you have any advice? Note that "export as namespace" doesn't help because our user code is already modules, not scripts.

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 với hai mẫu khai báo và các chẩn đoán được trích dẫn trong issue. Theo dõi cách export =, declare globalexport as namespace được xử lý, sau đó xác định liệu một cách tiếp cận được hỗ trợ hoặc một thay đổi ngôn ngữ có thể đáp ứng cả việc sử dụng dưới dạng module và việc sử dụng toàn cục hay không; chỉ được xem là hoàn tất khi có một cách giải quyết rõ ràng và đã được kiểm thử.

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

Đánh giá

Công nghệ
javascript, 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
Cần làm rõ
Mức phù hợp với người mới
25/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.