microsoft / microsoft/TypeScript
Add type definition for Math.sumPrecise (ES2025 / TC39 proposal)
Chưa có ai nhận issue này.
- 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ả
---
### Bug report
#### 📝 Description
`Math.sumPrecise` is part of the [TC39 `proposal-math-sum`](https://github.com/tc39/proposal-math-sum) which reached **Stage 4 on 2025-07-28**, making it part of **ES2026** (not ES2025 as originally stated — the proposal missed the ES2025 cutoff by about one month). Major runtimes like **Bun**, **Firefox 137+**, and **Safari 18.4** have already implemented it, though V8/Node.js has not yet.
However, TypeScript does **not** include type definitions for this API — searching through all `lib.es*.d.ts` files yields no results for `sumPrecise`.
#### 🐛 The problem
This causes a compile error:
```
Property 'sumPrecise' does not exist on type 'Math'. ts(2339)
```
Users are forced to either:
- Use workarounds like type augmentation (`global.d.ts`)
- Fall back to `@ts-expect-error`
- Use incorrect alternatives like `Array.reduce((a, b) => a + b)` which lose precision
#### ✅ Expected behavior
The `interface Math` should be extended in `lib.esnext.math.d.ts`:
```typescript
interface Math {
/**
* Returns the sum of the values in the iterable using a more precise
* summation algorithm than naive floating-point addition.
* Returns `-0` if the iterable is empty.
* @param numbers An iterable (such as an Array) of numbers.
* @throws {TypeError} If `numbers` is not iterable, or if any value in the iterable is not of type `number`.
* @throws {RangeError} If the iterable yields 2^53 or more values.
*/
sumPrecise(numbers: Iterable): number;
}
```
#### 🔗 Related
- TC39 Proposal: https://github.com/tc39/proposal-math-sum
- Stage 4 meeting notes: https://github.com/tc39/notes/blob/main/meetings/2025-07/july-28.md#mathsumprecise-for-stage-4
- MDN Docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sumPrecise
- Firefox 137+: shipped
- Safari 18.4 (JavaScriptCore): shipped
- Bun: shipped
- V8 / Node.js / Chrome: not yet
---
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu trong lib.esnext.math.d.ts và so sánh khai báo cần thiết cho Math.sumPrecise với đề xuất TC39 được liên kết và các định nghĩa Math hiện có. Công việc hoàn tất khi interface Math cung cấp sumPrecise với chữ ký iterable-of-number được ghi trong tài liệu và TypeScript chấp nhận các lệnh gọi mà không cần augmentation hoặc suppression lỗ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ệ
- javascript, typescript
- Lĩnh vực
- tooling
- Loại issue
- Tính năng
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 84/100