Skip to content

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

Open
@ubershmekel

Description

@ubershmekel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions