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

Yeah that's deliberate. They're proposing that Typescript should be valid JavaScript, just with the type hints ignored by JS engines.

Seems like a very reasonable proposal to me.

It is quite similar to Python's type hint system. Python's is kind of rubbish because there are multiple competing type checkers with different semantics and most people use the crap one (Mypy). I can't see that being a problem here - essentially everyone uses Typescript and it's very good.




>most people use the crap one (Mypy)

idk, I wouldn't go this far. Mypy is slow, but it's probably the most correct, and it allows for configurations pyright refuses to. For instance, the maintainers won't add an option to allow variable redefinition/shadowing, seemingly because they don't understand the difference between a variable and a binding (https://github.com/microsoft/pyright/discussions/2441). As for Pyre, last I checked it had a lot of false positives that Mypy doesn't.

Besides all that, some people want to use a checker that isn't exclusively developed by a huge company (Microsoft, Google or Facebook).


I dunno I've run into very basic bugs in Mypy and I even went as far as trying to fix them myself. If you had read the code you wouldn't have such a high opinion of it!

In contrast Pyright seems to get pretty much everything right, even really subtle things, and if it is really a bug then the guy that maintains it is insanely good at fixing them. Seriously check out how many open/closed issues there are.

As for variable redefinition, Python stupidly doesn't prescribe semantics so it's perfectly valid for it to behave like that. Definitely arguable which way it should go and I think for clarity it's much better to use different names anyway. It's not because they don't understand anything.

Mypy has way crazier behaviours anyway, e.g. implicit making types optional. Different behaviour depending on the syntax used to add types, etc.


>If you had read the code you wouldn't have such a high opinion of it!

That's probably true of most code :P

>Definitely arguable which way it should go and I think for clarity it's much better to use different names anyway. It's not because they don't understand anything.

I agree it's debatable which behavior is better. The reason I claim a lack of understanding is because of a comment (albeit likely a flippant one) one of the maintainers made in the issue I linked:

>When a variable or parameter has a declared (annotated) type, it's the job of a type checker to validate that all values assigned to that variable are compatible with the declared type. This is how type checking works in all languages that I'm familiar with.

This just isn't true; many strongly-typed languages allow variable shadowing, especially within lexical scopes. Some, like Rust, even allow rebinding within the same scope.




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

Search: