microsoft / microsoft/TypeScript

The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.ts(2363)

Aperta
#45,460 1 commento 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Experience Enhancement Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Suggestion

The following code errors:

      const x: Number = 5;
      const y = 5 - x;

With this:

The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.ts(2363)

Which is super confusing because it is a number. But I didn't realize the problem was the first letter capitalization. Number vs number.

🔍 Search Terms

right-hand side of an arithmetic

✅ Viability Checklist

My suggestion meets these guidelines:

  • [v] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [v] This wouldn't change the runtime behavior of existing JavaScript code
  • [v] This could be implemented without emitting different JS based on the types of the expressions
  • [v] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • [v] This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Would be nice if there was an error during the assignment, is Number also a number? Another option is error 2363 could mention this potential issue. E.g.

The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. Not 'Number' .ts(2363)

And replace 'Number' with whatever type was actually found.

📃 Motivating Example

      const x: Number = 5;
      const y = 5 - x;

Minor typos should have a clear error message.

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.

Direzione di ricerca

Inizia individuando il diagnostic 2363 nel compilatore TypeScript e i test che coprono gli errori nelle operazioni aritmetiche. Verifica come viene selezionato il tipo dell’operando segnalato, quindi aggiorna il comportamento del diagnostic in modo da identificare un tipo come 'Number' e aggiungi la copertura per l’esempio motivante.

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

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.