Hacker News new | past | comments | ask | show | jobs | submit login

Nice, so this is the equivalent of `with` and context mangers in Python. I like it.

I generally avoid new TS features (apart from typing that gets compiled away) until it looks like they are going to make their way into JavaScript, anyone know if thats being considered?

--

Edit: Yes it's being considered, looks likely, but not decided - https://github.com/tc39/proposal-explicit-resource-managemen...




TypeScript only implements JS features that make it to Stage 3, the only exception being decorators in the past which never went beyond Stage 2 in their previous form.


Those first draft decorators never made it past Stage 1. That's also why Typescript required a compile-time flag that began with `--experimental` before you could use them. It's amazing how many projects put an `--experimental` flag into Production code. (Thanks, Angular.)



> Nice, so this is the equivalent of `with` and context mangers in Python.

Well, half of it at least :)

Python has both enter and exit, while this proposal only has the exit half.


More importantly, it does not allow distinguishing between successful completion and a thrown exception. Which may or may not be such a great feature in the first place, but still.


TBF the `__enter__` hook is not the most useful.


The article mentions that this proposal is in stage 3 for Javascript, so will probably be refined a bit more https://tc39.es/process-document/


Things rarely change at all once they're at stage 3. That's why TS waits until that stage before implementing. There might be a minor tweak in some edge cases but stage 3 is usually "done".


Which is funny since Javascript had `with` before (that did something completely different) that was overly abused and thus removed.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: