microsoft / microsoft/TypeScript

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

Open
#45,460 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Experience Enhancement Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating diagnostic 2363 in the TypeScript compiler and the tests that cover arithmetic-operation errors. Confirm how the reported operand type is selected, then update the diagnostic behavior to identify a type such as 'Number' and add coverage for the motivating example.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.