Repository: TypeScript
Issue: Add the strictMathChecks option to allow for less complex code with math operations
Labels: Suggestion,Awaiting More Feedback

# Suggestion

<!--
  Please fill in each section completely. Thank you!
-->

## 🔍 Search Terms

<!--
  💡 Did you know? TypeScript has over 2,000 open suggestions!
  🔎 Please search thoroughly before logging new feature requests as most common ideas already have a proposal in progress.
  The "Common Feature Requests" section of the FAQ lists many popular requests: https://github.com/Microsoft/TypeScript/wiki/FAQ#common-feature-requests

  Replace the text below:
-->

"undefined math"

## ✅ Viability Checklist

<!--
   Suggestions that don't meet all these criteria are very, very unlikely to be accepted.
   We always recommend reviewing the TypeScript design goals before investing time writing
   a proposal for ideas outside the scope of the project.
-->
My suggestion meets these guidelines:

* [X] This wouldn't be a breaking change in existing TypeScript/JavaScript code
* [X] This wouldn't change the runtime behavior of existing JavaScript code
* [X] This could be implemented without emitting different JS based on the types of the expressions
* [X] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
* [X] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).


## ⭐ Suggestion

<!-- A summary of what you'd like to see added or changed -->
Typescript currently produces an error when comparing undefined or null in math operations. While this may be wanted in some situations, not everyone may want this and it has been a big source of errors in my code. I would like to suggest the addition of a tsconfig option called "strictMathChecks" that would default to true (current behavior) and, when false, would allow for comparison with undefined or nan in math operations.
The reasons why I believe this would make sense are the following:

- The current alternative to this is doing Number(variable) on the variable that is producing the error, which turns it into NaN and can then be compared (always returning false) and produces the same result
- In JavaScript, you can compare null/undefined in math operations and no error will be thrown, which does the same as using NaN like shown above.

Here are some short examples:
```js
undefined > 50 // returns false in JS but throws an error in TS
NaN < 50 // returns false and does not throw an error in TS
null <= 100 // returns false but throws an error in TS
```

## 📃 Motivating Example

<!--
  If you were announcing this feature in a blog post, what's a short explanation that shows
  a developer why this feature improves the language?
-->
TypeScript will now allow you to use undefined/null values in math operations when the strictMathChecks option is set to false. This allows for less redundant code.

## 💻 Use Cases

<!--
  What do you want to use this for?
  What shortcomings exist with current approaches?
  What workarounds are you using in the meantime?
-->
As I explained above, the workaround for this error is pointless since this syntax is valid in JS, and applying it does not change the behavior at all, so it just becomes a minor inconvenience.