4 ms·
Yes. All JS code – including recent ES* flavors – is valid TypeScript.
by steadicat 8y ago
Yes. All JS code – including recent ES* flavors – is valid TypeScript.
- recursive 8y agoAlmost. This is valid javascript. [1].push("foo");
- alangpierce 8y agoTypeScript code can be transpiled and executed even if there are type errors (just like how a linter doesn't stop you from running your code), so in that sense, it's also valid TypeScript.
- thomasfoster96 8y agoThis is true of syntax, but it’s not true of the language semantics. There is plenty of perfectly valid JavaScript that isn’t valid TypeScript, so integrating TypeScript into the ECMAScript standard would require something similar to ES5’s “use strict”. I can’t find the link which details this right now, but I believe there are/were some cases where Flow’s syntax isn’t strictly a superset of JavaScript (to do with generics and comparison operators). I’m not sure whether TypeScript has the same problem or not.