microsoft / microsoft/TypeScript

Make standard library types more polyfills‑friendly

Đang mở
#63,069 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.

Domain: lib.d.ts 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ả

A significant number of ECMAScript / web standards features that have recently standardized (like [`Iterator.concat`](https://github.com/tc39/proposal-iterator-sequencing)) are still missing from the TypeScript standard library. There are ECMAScript proposals (like [`Iterator.zip`](https://github.com/tc39/proposal-joint-iteration)) that are supported by modern browsers but still lack corresponding type definitions. Finally, many projects intentionally target older TypeScript versions with old standard library types.

I am working on types for the [`core-js` polyfill library](https://github.com/zloirock/core-js), which is used on most websites, so it makes a lot of sense to add type definitions for it. While doing this work, I have encountered some significant issues:

- Some DOM types, for example `URL`, are declared as ambient variable declarations with type literals in `lib.dom.d.ts`. This approach does not allow declaration merging. *Possible solution:* define them via interfaces (like in ECMAScript types) to allow declaration merging.

- The use of getters/setters. For example, [`ArrayBuffer` defines the detached property via a getter](https://github.com/microsoft/TypeScript/blob/3fc1f264de2aacae0c008eb4295e66833ade36d9/src/lib/es2024.arraybuffer.d.ts#L28). This makes it impossible to create a compatible polyfill type for different targets. Similar issues often cause conflicts between different type libraries. In most similar cases, accessors are declared as readonly properties, and this does not cause any problems.

If there were some mechanism for conditional type usage, it could make the standard types more polyfills‑friendly.

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 việc xem xét các khai báo ambient trong lib.dom.d.ts và accessor của ArrayBuffer trong src/lib/es2024.arraybuffer.d.ts, cùng với ngữ cảnh liên quan được liên kết của core-js và đề xuất ECMAScript. Công việc được hoàn tất khi có một cơ chế đã được thống nhất, giúp các kiểu của thư viện chuẩn tương thích với polyfill và các library target TypeScript cũ hơn, cùng với các thay đổi tương ứng cho thư viện.

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.