HACKER Q&A
📣 rrishi

Will we see a TypeScript for Python?


Is there a need for such a thing like JS needed it? Is it viable?


  👤 PaulHoule Accepted Answer ✓
Python has an optional typing system which helps your IDE complete things and can be checked with tools like

https://mypy.readthedocs.io/en/stable/index.html

Plus there are compilers which can make faster code if you add static types

https://cython.readthedocs.io/en/latest/src/quickstart/cytho...


👤 abeppu
It's true that python has support for typing, and I do find that mypy helps produce better python code.

But I think a meaningful issue is that python's rich ecosystem of datascience and ML tooling often is at odds with meaningful type annotations. Roughly, you can end up with signatures that indicate that a value is a DataFrame or an ndarray or whatever, but there are a bunch of implicit assumptions on what columns are defined, or what how the shapes of two ndarrays line up, etc. It's easy for a codebase to end up paying the upfront cost of providing annotations, but without actually getting an improved ability to reason about or refactor code.


👤 peruvian
Python 3 has types and you can use Pydantic for validation.

https://docs.pydantic.dev


👤 user3939382
In the abstract we have Psalm for PHP which I think is likely to eventually get rolled into PHP’s native type system. It’s so robust the major IDEs haven’t fully implemented it yet.

It doesn’t turn PHP into Haskell or anything but huge swaths of bugs are eliminated.


👤 nilsbunger
Python typing is optional and only checked statically, just like typescript typing. What else would a “Typescript for Python” add?

👤 jasfi
If you consider a language besides Python itself (which has optional typing), Nim could be an option, as the syntax is similar.

👤 speedgoose
As other mentioned, Python has already some tools around strong typing.

However they aren’t as extensive as TypeScript is to JavaScript. The community is also not much into types so you don’t have collections like Definitely Typed.

But the need exists and I guess it’s a matter of time until a tool becomes as popular and complete as typescript.


👤 hot_gril
JS doesn't need TypeScript. When's the last time TS saved your JS project from disaster?

👤 findjashua
pyright

👤 otabdeveloper4
Probably never. Modern Python is a joke, and so are attempts at to typify it like mypy.