News for hackers. Stuff that matters.
Re:Future of TypeScript on ESLint by bauerd on Friday January 18, 2019 @03:44PM (#18942886)
Is JS a strict subset of TypeScript?
Re:Future of TypeScript on ESLint by steadicat on Friday January 18, 2019 @03:52PM (#18942953)
Yes. All JS code – including recent ES* flavors – is valid TypeScript.
Re:Future of TypeScript on ESLint by thomasfoster96 on Friday January 18, 2019 @06:41PM (#18944177)
This 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.

Re:Future of TypeScript on ESLint by recursive on Friday January 18, 2019 @06:37PM (#18944160)
Almost. This is valid javascript.

    [1].push("foo");
Re:Future of TypeScript on ESLint by alangpierce on Friday January 18, 2019 @07:00PM (#18944279)
TypeScript 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.
Re:Future of TypeScript on ESLint by tazard on Friday January 18, 2019 @06:28PM (#18944112)
Technically typescript is a strict superset of JS, but yes
Re:Future of TypeScript on ESLint by lhorie on Friday January 18, 2019 @07:39PM (#18944467)
Technically technically, it turns out that no it's not. I recently realized that `a<b>(x)`, `a<b,c>(x)` and variations mean something completely different in TS than they do in JS.
Re:Future of TypeScript on ESLint by chrismorgan on Saturday January 19, 2019 @04:33AM (#18946168)
And that’s exactly why Rust has the turbofish (a :: before the <), to resolve that syntactic ambiguity. TypeScript could have resolved it by requiring a . before the <, but it didn’t, and so you can devise contrived cases like this where it differs from JavaScript.
Re:Future of TypeScript on ESLint by spraak on Friday January 18, 2019 @11:32PM (#18945346)
Is that denoting generics? Can you give an example?
Re:Future of TypeScript on ESLint by alangpierce on Friday January 18, 2019 @11:58PM (#18945416)
Yeah, it's the syntax when calling a generic function, e.g. `Array.of<number | null>(1, 2, null);` has return type `Array<number | null>`. You usually don't need to specify the type since TypeScript can figure it out, but sometime's it's necessary to specify it explicitly.

TypeScript compiles `a<b>(x)` to `a(x)`, which is a function call, but when run as plain JS, `a<b>(x)` is a less-than and greater-than comparison between a, b, and x.

Re:Future of TypeScript on ESLint by tazard on Sunday January 20, 2019 @09:57AM (#18953303)
That's interesting and so obvious now that you mention it. Thanks for the clarification.