Differences from JavaScript
JS+ is a TypeScript superset. By default all JavaScript and TypeScript syntax is valid in JS+, expect for the following exceptions:
Breaking changes
Section titled “Breaking changes”- Everything is strict by default •
use strict - CommonJS is not supported. Everything is a ESM by default •
import/export document.allis not allowed MDN- Typeof null operator •
typeof null -> 'null' - Negative array subscript
- Chained comparisons • Chained comparisons work out of the box
Errors/Warnings
Section titled “Errors/Warnings”These errors/warnings won’t block you from compiling JS+ into TypeScript/JavaScript
undefinedshould not be used explicitly. For nullish initializations usenullinstead-0,0/0don’t make sense- Don’t implicitly coerce strings with
+. UseparseInt()orparseFloat()instead isNaN()is a deprecated artifact. UseNumber.isNaN()insteadDateis a deprecated artifact. UseTemporalinstead- Errors/warnings related to better syntax implementations (Features)
- Don’t use JavaScript
#private modifier. Prefer TypeScriptprivatekeyword instead @ts-checkand@ts-nocheckare not allowed. JS+ is typechecked by default and typechecking cannot be turned off@ts-ignoreis a deprecated artifact. Use@ts-expect-errorinstead
This table showcases difference between TypeScript and JS+ errors with JavaScript syntax from the Wtfjs list
| Wtf? (Idk man) | 🥴 JavaScript | 🧠 TypeScript | 💚 JS+ |
|---|---|---|---|
[] == ![]; | true | ✅ Error | ✅ Error |
true == [];true == ![];false == [];false == ![]; | falsefalsetruetrue | ✅ Error ✅ Error ✅ Error ✅ Error | ✅ Error ✅ Error ✅ Error ✅ Error |
!!"false" == !!"true";!!"false" === !!"true" | truetrue | ✅ Error ✅ Error | ✅ Error ✅ Error |
"b" + "a" + +"a" + "a"; | 'baNaNa' 🍌 | 👍 | ✅ Error for + coercion |
NaN === NaN;-0 === 0;NaN === 0/0; | falsefalsefalse | ✅ Error 👍 ✅ Error | ✅ Error ✅ Error for -0✅ Error |
Object.is(NaN, NaN);Object.is(-0, 0);Object.is(NaN, 0/0); | truefalsetrue | 👍 👍 👍 | 👍 ✅ Error for -0✅ Error for 0/0 |
| It’s a fail | fail | 👍 | 👍 (for real?) |
!![]; | true | ✅ Error | ✅ Error |
!!null;0 == false;"" == false; | falsetruetrue | ✅ Error ✅ Error ✅ Error | ✅ Error ✅ Error ✅ Error |
document.all instanceof Object;typeof document.all;document.all === undefined;document.all === null;document.all == true; | trueundefinedfalsefalsetrue | 👍 👍 👍 👍 ✅ Error | ✅ Error for document.all✅ Error for document.all✅ Error for document.all✅ Error for document.all✅ Bro stop with this syntax |
Number.MIN_VALUE > 0; | true | 👍 | 👍 |
typeof null; | 'object' | 👍 | 'null' Read more |
[1, 2, 3] + [4, 5, 6]; | '1,2,34,5,6' | ✅ Error | ✅ Error |
const a = [,,,];a.length;a.toString(); | 3',,' | 👍 👍 | 👍 👍 |
[] == ''; [] == 0; [''] == ''; [0] == 0; [0] == ''; [''] == 0; [null] == ''; [null] == 0; [undefined] == ''; [undefined] == 0; [[]] == 0; [[]] == ''; [[[[[[]]]]]] == ''; [[[[[[]]]]]] == 0; [[[[[[null]]]]]] == 0; [[[[[[null]]]]]] == ''; [[[[[[undefined]]]]]] == 0; [[[[[[undefined]]]]]] == ''; | truetruetruetruefalsetruetruetruetruetruetruetruetruetruetruetruetrue | ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error | ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error ✅ Error |
Number();Number(undefined); | 0NaN | 👍 | ✅ Error for undefined |
parseInt('f*ck');parseInt('f*ck', 16);parseInt("Infinity", 10);parseInt("Infinity", 18);parseInt("Infinity", 19);parseInt("Infinity", 23);parseInt("Infinity", 24);parseInt("Infinity", 29);parseInt("Infinity", 30);parseInt("Infinity", 34);parseInt("Infinity", 35);parseInt("Infinity", 36);parseInt("Infinity", 37);parseInt(null, 24); | NaN15NaNNaN1823 | 👍 ✅ Error | 👍 ✅ Error |
true + true;(true + true) * (true + true) - true; // -> 3 | 23 | ✅ Error | ✅ Error |
typeof NaNtypeof Infinity | 'number''number' | 👍 👍 | 👍 👍 |
0.1 + 0.2 | 0.30000000000000004 | 👍 | 👍 |
1 < 2 < 33 > 2 > 1 | truefalse | ✅ Error | 👍 duh it works |
| Funny math | |||
| Addition of RegExps | |||
Strings aren’t instances of String | |||
| Calling functions with backticks | |||
| Callception | |||
| … |