Remix.run Logo
nine_k 5 days ago

> TypeScript compiler essentially treats types as a lint

Sorry, I think you've been swindled.

The Typescript compiler is made by Miscrosoft and is called tsc. It very much heeds the type annotations, and very much rejects ill-typed programs. An LSP based on it does the same in an editor. Also tsc supports refinement types via flow control analysis and a bunch of other static correctness checks.

Deno, bun, swc are not true compilers like tsc, they don't do much correctness checking at all. They discard al the type info, and then operate on pure JS (modules conversion, minification, etc).

debugnik 4 days ago | parent | next [-]

> and very much rejects ill-typed programs

No it doesn't. Even on the strictest settings, Typescript is unsound in trivial ways, which I hit every time I use it in anger (e.g. undefined in unassigned variables). And Microsoft libraries seem perfectly ok with asserting their type errors away without any validation, specially for JSON values.

I had a similar experience with Python until I found Pydantic.

I haven't had a chance to try Elixir's new type system (is it ready yet?), but at least their strong-arrow model would ensure that runtime checks for dynamically-typed values are done eventually.

nine_k 4 days ago | parent | next [-]

This is sadly so; TS's type system is unsound. But so is C#'s, in ways much more egregious that in TS. Despite that, both languages are very usable in practice, and their static checks prevent a very wide range of problems common in languages without a static type system.

If you need bulletproof soundness and JS as the runtime, you have Purescript %)

debugnik 4 days ago | parent [-]

> in ways much more egregious that in TS

Which ways you say? As far as I know: both TS and C# can carry hidden nulls; both made the mistake of covariant arrays, but C# actually type checks accesses at runtime; and the other unsound case I know of in C# involves a runtime type check as well. Meanwhile, TS (and Python) allow fully unchecked casts into the wrong type.

> both languages are very usable in practice

Agreed, but I still consider TS too unsound in trivial cases for the claim I replied to, despite its expressive power. I think this industry is lacking severely when it comes to basic software correctness.

pdimitar 2 days ago | parent | prev [-]

> I haven't had a chance to try Elixir's new type system (is it ready yet?)

Sadly no, and it will likely not be fully ready for years still. It's not a funded work and only a few people are working on it (AFAICT) and the core team understandably wants gradual movement and no incompatibilities.

Elixir made me rediscover love for programming and gave me productivity I never dreamed of. But after using it for 9 years, the lack of static typing really started getting on my nerves. There are only so many times you can do manual exhaustive pattern-matching on the hot paths that yell errors in production before you start feeling envious of Rust and Haskell.

ZephyrBlu 4 days ago | parent | prev | next [-]

You can lie to TypeScript extremely easily in a way that you can't do in strongly typed languages.

colejohnson66 4 days ago | parent [-]

Even in a strongly typed language like Java or C#, nothing stops `(string)(object)42`. It all compiles and fails at runtime, like TypeScript.

No matter what language you’re in, the second you use a cast, you’re asserting to the compiler that you know more than it.

nurettin 4 days ago | parent | prev [-]

I think they are confused by the tslint project, which is different than tsc and is not supported by Microsoft

LoganDark 4 days ago | parent | next [-]

I used tsc directly to develop https://github.com/LoganDark/waifu2x-unlimited. I have experience with tsc.

nine_k 4 days ago | parent | prev [-]

Or maybe even https://github.com/bloomberg/ts-blank-space

But I bet on swc, which is used by Deno internally, or on the Bun's built-in transpiler that does things similar to swc or ts-blank: they all assume that the code is semantically correct (not just syntactically valid) Typescript, and then just ignore the Typescript-specific bits.