Hacker News new | ask | show | jobs
by enlyth 1366 days ago
I wish Microsoft would make a language almost exactly like Typescript, but where code has to be strictly typed (no any, unknown, etc.) and it would compile to a normal binary, with some sort of GC, for multiple platforms.

It would hit the sweet spot for me, I know Rust is popular these days, but it seems like it's made for type astronauts, and sometimes I just want to write some code and get things done quickly and don't care about squeezing out every last drop of bare metal performance or abstracting seven layers of types to please a borrow checker.

6 comments

It sounds like you want “deno compile” (https://deno.land/manual@v1.25.4/tools/compiler) plus “no-explicit-any” eslint rule (https://github.com/typescript-eslint/typescript-eslint/blob/...).

Or are you wanting a language with different semantics that could be compiled to actual machine code?

That still allows `x as string` and many other traps. Typescript just isn't type-safe, and this has bitten me so many times in real world projects with strict mode and all. The best thing I can say about Typescript is that it's an improvement over Javascript.
You want C# with dotnet AOT.
You beat me to it. Exactly this - use C#.
Last I checked C# didn't have an algebraic type system...
But F# is sitting in the corner with an eyebrow cocked suggestively.
C# does not have "type" keyword and really lacks behind with enums. You can theoretically replace algebraic type system with inheritance, however that's a lot of times ugly and you propablly shouldn't do it.
I suppose AssemblyScript fits some of those points: no any or unknown; compiles to a binary; GC; cross-platform.
> I wish Microsoft would make a language almost exactly like Typescript, but where code has to be strictly typed (no any, unknown, etc.) and it would compile to a normal binary, with some sort of GC, for multiple platforms.

Isn't that what ReasonML is for?

There’s no such thing as “fully sound” type system, outside theorem provers like Lean. Every type system has a trapdoor. Rust has “unsafe”. Haskell has “unsafePerformIO”. And TypeScript has “any”. Soundness is just as much a property of a language’s culture as its implementation. Practically I find that TypeScript is sound enough for my purposes when most of the strictness options are enabled.
About 90% of any can and should be replaced with unknown which is infinitely more useful and a lot safer.

There is an example signature at the end of the article; (x: any) => string, this error would not fly if x were unknown.

On of the few remaining scenarios where any might be necessary is to narrow down a generic param, ie <T extends Something<any>>.

How about F#?