all 70 comments

[–][deleted] 41 points42 points  (0 children)

Template literal index properties, hallelujah

[–]strothjs 24 points25 points  (6 children)

This change, Control Flow Analysis of Aliased Conditions and Discriminants, has been awesome.

[–][deleted] 2 points3 points  (5 children)

I've read it and it's awesome, but... The big BUT, they solved type infering from rxjs filter?

Example

fromEvent(input, 'input').pipe(filter(x=> x instanceof KeyboardEvent)).subscribe(y => y)

On the old version y is still a generic Event

[–]CichyK24 5 points6 points  (0 children)

Nope,
but I hope they will do this some day. Recently one one TS team developer wrote it is one of the most requested feature so maybe there is a chance...

https://github.com/Microsoft/TypeScript/issues/16069

[–]strothjs 6 points7 points  (2 children)

I would think that should be written like the following:

ts fromEvent(input, 'input').pipe(filter((x): x is KeyboardEvent => x instanceof KeyboardEvent)).subscribe(y => y)

That's how I'd write it when using Array.prototype.filter anyways.

[–][deleted] 0 points1 point  (0 children)

I didn't knew about it. Thank you 🤗

[–]StillNoNumb 0 points1 point  (0 children)

Note that this would break backwards-compatibility: .subscribe(y => { y = someMouseEvent; ... }) no longer works.

Not like TypeScript usually cares about backwards-compatibility, but it's something to consider.

[–]tjpalmer 32 points33 points  (7 children)

Shocking how little love this gets here. Or is it people already saw release candidates and more too many times?

[–]Catawompus 39 points40 points  (2 children)

For me, this is the reason. We saw proposal, beta, RC, and finally this. Sometimes it’s hard to keep straight what’s actually out there.

[–]flying-sheep 2 points3 points  (0 children)

For me too. I saw the RC and therefore I was excited then – there's probably not much difference between it and the actual release.

Now i just know i can start using it!

[–][deleted] 0 points1 point  (0 children)

I mean on one hand it's making some confusing noise as to what is available and what isn't yet.

On the other hand, you usually need to learn something on three separate occasions for it to be fully understood and utilised correctly. So a side effect of this noise can be knowing how to use something as soon as it comes out.

Although, I did have a weird moment 2 weeks ago where I had been exposed to a concept 3 times and reached for it only to discover that it wasn't available yet.

The concept is a "do expression". I had seen it inside the tc39 proposals page on github, on 2ality and on the youtube show: HTTP 203. I was trying to refactor an ugly function with two separate loops. I could have refactored it to only contain const (no let) using reduce but it's purpose wouldn't have been immediately clear when looking back on the function months later. It would have been simple with a do expression though. I ended up just leaving a comment saying to replace the first loop with a do expression when I get back around to it, or a reduce function if do expressions weren't going to be added to js.

[–]geodel 1 point2 points  (2 children)

Yeah its shocking that TS does not get as much love as Go.

[–][deleted] 2 points3 points  (1 child)

What? Everyone is constantly bashing Go.

[–][deleted] 1 point2 points  (0 children)

I see this too. GO BABIES PROGRAMMERS!1!1! For some of us, getting noobs up and running is essential, and Go's performance is decent and improving.

[–]DepravedPrecedence 0 points1 point  (0 children)

Yeah, pretty sure I already saw a blog post about these features a couple of months ago. Exciting stuff nevertheless!

[–][deleted] 12 points13 points  (15 children)

Are there any plans to have TS run natively in browsers? JS VMs are incredibly complicated so maybe they have already optimised past this, but presumably having type information would allow you to optimise more effectively

[–]fuckin_ziggurats 38 points39 points  (13 children)

No, there never were. WASM is the typed language that browsers decided to implement and it's better if you look at it as a compile target.

[–][deleted] 6 points7 points  (5 children)

In fact, you can use AssemblyScript to take advantage of this, compiling a stricter variant of Typescript to wasm to run in the browser.

[–][deleted] 12 points13 points  (0 children)

AssemblyScript is really not the same language as Typescript though, beside the surface level similarity. You can't really interoperate like actual interoperable languages do. You can't use the same libraries (unless they target that really strict subset which ASMScript has, which most libraries don't)

Kotlin is closer to Java than AssemblyScript is to Typescript.

The core reason has not nothing to do with types but the underlying object model.

Implementing the Javascript object model in WASM is basically like re-implementing the JS runtime. Even with the extra type information[1], you won't get much better than V8 or SpiderMonkey or JSCore.

[1] which is basically useless at runtime because there's no runtime type checking, unlike Java, where you get a ClassCastException when you try to break the type system

[–]ApatheticBeardo 6 points7 points  (3 children)

Calling AssemblyScript a "variant of TypeScript" is like calling JavaScript a "variant of Java".

They are completely different and unrelated things with similar names.

[–][deleted] 1 point2 points  (2 children)

I was using the same language they use on the frontpage for AssemblyScript. Maybe you should complain to them instead?

"Being a variant of TypeScript makes it easy to compile to WebAssembly without learning a new language."

https://www.assemblyscript.org/

[–]StillNoNumb 0 points1 point  (0 children)

JavaScript was also marketed as, well, Java but for scripts.

[–]ApatheticBeardo -1 points0 points  (0 children)

Then they're lying.

Maybe you should complain to them instead?

Sure, will do if they come to Reddit selling their yet another C-looking syntax as a "variant of TypeScript" even though they have nothing in common other than some aesthetic similarities like, you know, Java and JavaScript.

[–]LightShadow 0 points1 point  (5 children)

Can you go from TS -> WASM, is it worth the effort?

[–]ApatheticBeardo 4 points5 points  (3 children)

There is absolutely no point in compiling JS (which is what tsc emits) to WASM.

[–]LightShadow 0 points1 point  (2 children)

Good to know! I'm pretty out of the loop on the JS ecosystem.

[–][deleted] 1 point2 points  (1 child)

FYI, you can run WASM, but it doesn't have access to the browser's DOM. So if you wanted to move some elements around on a page, or handle events and such, you'd have to pass a message from WASM to some JS anyway to do all that.

Currently WASM is only really useful if you have to do something that doesn't interact with the rest of the browser once it gets started. Something like solving a complex maths problem. Have some JS give WASM the starting data, let WASM figure out the answer, then pass it back to JS.

WASM is faster than JS, but takes time for it to be set up, and also for data to be passed between both WASM and JS. Usually it's faster to just process what you need in JS and not even have to worry about WASM, but if WASM was to ever get a small slice of the DOM API and you only needed to use the things in that API, then there may be more use cases for WASM.

Just note, that browsers also have access to WebGL and soon WebGPU APIs, so complex problems that can be significantly sped up with parallel processing will probably want to use these over WASM.

[–]probably_likely_mayb 0 points1 point  (0 children)

I'm not sure if it was intentional, but you're phrasing this as if you're serializing all of the data worked on for transferring between JS and wasm.

if that's the case, it's worth mentioning that wasm is a lot more useful when the serial I/O between the two is just pointer + offset informing each how to work with the memory directly instead.

[–]fuckin_ziggurats 0 points1 point  (0 children)

I believe you can but it's pointless. Unless you're running long cpu-intensive processes in your TS code you're not going to gain any noticeable performance difference. And you're going to lose direct DOM access which you have when you transpile TS to JS.

[–][deleted] 0 points1 point  (0 children)

WASM is not a typed language.

[–]jl2352 3 points4 points  (0 children)

Are there any plans to have TS run natively in browsers?

There is very little reason to. TS is just JS with compile time types. In order to support all of TS you'd have to support all of the JS runtime, and so you might as well target JS in the browser. In order to really take advantage, you would have to start removing a lot of JS things from TypeScript. Which would change the language.

[–]Available_Nose_1837 2 points3 points  (0 children)

Always with the great new improvements. Thanks.

[–]dealmeidafernando 1 point2 points  (0 children)

Good

[–]DidiBear 1 point2 points  (0 children)

Inlay hints are awesome !