microsoft / microsoft/TypeScript

Add type definition for Math.sumPrecise (ES2025 / TC39 proposal)

Offen Anfängerfreundlich
#63,427 8 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bug Domain: lib.d.ts Help Wanted Needs Human Review
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung


Bug report
📝 Description

Math.sumPrecise is part of the 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:

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>): number;
}
🔗 Related

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in lib.esnext.math.d.ts und vergleiche die für Math.sumPrecise erforderliche Deklaration mit dem verknüpften TC39-Vorschlag und den vorhandenen Math-Definitionen. Die Arbeit ist abgeschlossen, wenn die Math-Schnittstelle sumPrecise mit der dokumentierten Signatur für ein Iterable von Zahlen bereitstellt und TypeScript Aufrufe ohne Erweiterung oder Fehlerunterdrückung akzeptiert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Aktiv
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
84/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.