News for hackers. Stuff that matters.
Re:Why Become a TypeScript Fan? by AzzieElbab on Wednesday March 10, 2021 @11:22AM (#26412867)
Are they planning to implement pattern matching in ts? It seems like such a good fit for language type system
Re:Why Become a TypeScript Fan? by WorldMaker on Wednesday March 10, 2021 @11:58AM (#26413368)
At this point TS is trying to keep runtime syntax in line with TC-39 (the language committee in charge of JS) proposals that reach Stage 3 (and thus likely to reach Stage 4 and general acceptance/use in the browser).

There is currently a Stage 1 proposal for a pattern matching syntax presented to TC-39. If it reaches Stage 3 then it is presumed likely Typescript will implement it.

https://github.com/tc39/proposal-pattern-matching

Re:Why Become a TypeScript Fan? by wk_end on Wednesday March 10, 2021 @11:44AM (#26413163)
Not any time soon AFAIK. TS aims to be syntactically identical (minus the type system obviously) to JS, so no new constructs.

It’s not clear it’d be worthwhile, anyway - TS doesn’t support algebraic data types directly, which is the big use-case for pattern matching; and the type system is smart enough, with some careful massaging, to do exhaustiveness-checking when using ifs or switches and the standard pattern for simulating them.

Re:Why Become a TypeScript Fan? by dsirola on Wednesday March 10, 2021 @11:40AM (#26413098)
I don't think that's possible since types are not present at the runtime. They are just stripped away during compilation
Re:Why Become a TypeScript Fan? by alpaca128 on Wednesday March 10, 2021 @11:47AM (#26413208)
It would still be possible as long as all the necessary information is available at compile time.
Re:Why Become a TypeScript Fan? by flqn on Wednesday March 10, 2021 @12:06PM (#26413475)
Dispatch during pattern matching happens at runtime, which requires some means of discriminating the matched values with run-time information. Typescript doesn't provide any more runtime type information than Javascript does, and so it can't see the difference between "Object" and "Object" unless the object has fields that allow it to, such as the class constructor or programmer-specified values. I don't think that the compiler adding additional information to discriminate types other than what JS already provides fits with the design goals of Typescript being a language that only adds static typing.
Re:Why Become a TypeScript Fan? by alpaca128 on Wednesday March 10, 2021 @11:43AM (#26413136)
I hope so. As a Rust fan I was glad I learned TS for the situations I do more web-focused work. The union types are usually good enough as enum replacement, but good pattern matching would be yet another improvement.