Hacker News new | ask | show | jobs
by habitue 1988 days ago
> but at least on par with typescript

I wish this were true, but mypy is far behind typescript. For example, mypy has `Literal["foo"]`, but typescript has the ability to template literals like `"foo-${bar}"` etc, and actually understand the results statically.

That's not to say mypy isn't great, it has some really good stuff, but I mostly think you're underselling Typescript here.

1 comments

Huh, good to know. Does this issue apply to f-strings or are you talking about format methods? I did a brief look through issues and MyPy seems to support f-strings fine, but I’d 100% believe that there are still kinks to work out
Ah, so mypy supports fstrings, but not in types. So you can do

    Direction = Literal["left", "right"]
But this won't work:

    eft = "eft"
    ight = "ight"
    Direction = Literal[f"l{eft}", f"r{ight}"]
(Yes, this is super contrived, I bad at coming up with examples, but https://mariusschulz.com/blog/string-literal-types-in-typesc... shows some realistic examples where it's useful in typescript)