microsoft / microsoft/TypeScript

Incorrect error message on export assignment in `.d.ts` file

Đang mở
#33,341 0 bình luận 5 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ả

TypeScript Version: 3.5.3

Search Terms:

An export assignment cannot be used in a namespace.

Code

This is pretty niche, but I think it has general implications...

The current /lib/typescript.d.ts file is modelled as essentially a CommonJS file where at the end of the file, it has export = ts; which exports the whole namespace. The actual /lib/typescript.js though will place itself in the global scope as ts if it isn't loaded as a CommonJS module. In order to express that ts is available as a global variable, it requires code like this to be placed in a .d.ts file:

import * as _ts from "typescript";

declare global {
  namespace ts {
    export = _ts;
  }
}

Other methods of expressing this, like declare var ts: typeof _ts; only make the function shape of ts available, while the interfaces and type aliases and other type information is not accessible.

Expected behavior:

No errors.

Actual behavior:

The error TS1063: An export assignment cannot be used in a namespace occurs, but in VSCode, if the file is named globals.d.ts this error does not occur. 🤷‍♂ In all cases the code above does work like expected, making both the functional and type exports of the namespace available for code to be checked against.

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 chẩn đoán với đoạn khai báo được cung cấp, sau đó so sánh với hành vi khi tệp được đặt tên là globals.d.ts. Đọc các khai báo liên quan trong /lib/typescript.d.ts và ngữ cảnh runtime trong /lib/typescript.js. Hoàn tất khi mẫu hợp lệ không báo lỗi nào nhưng vẫn giữ cả các export chức năng và export kiểu.

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
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
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
42/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.