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

Aperta Adatta ai principianti
#63,427 8 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, typescript
Ambito
tooling

Direzione di ricerca

Inizia in lib.esnext.math.d.ts e confronta la dichiarazione necessaria per Math.sumPrecise con la proposta TC39 collegata e le definizioni esistenti di Math. Il lavoro è completo quando l’interfaccia Math espone sumPrecise con la firma documentata di un iterable di numeri e TypeScript accetta le chiamate senza un augmentation o la soppressione degli errori.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Domain: lib.d.ts Help Wanted Needs Human Review

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

Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 15h
PR unite (30g)
106

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/TypeScript

Tutte le issue di microsoft/TypeScript

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.