TS's type system is fun but a part of me always wonders how much faster TS's compiler would be if it was written in a compiled language (assuming "good implementation", which is a big assumption!)
TypeScript is surprisingly ok for compilers
21–30 of 245 posts
Re: TypeScript is surprisingly ok for compilers
#22Is that really suprising? Typescript is yet another language that has, kicking and screaming, picked up most of the ML featureset. I'd expect it to be, well, fine; the lack of real pattern matching is a pain, so it's going to be inferior to OCaml, but fine, no different from using C# or Swift or Dart or Kotlin or something of that ilk.
The biggest expressivity pain point in practice for me is try/catch not being an expression, so I can’t do const c = try { … }
const c = myAsyncFun()
.catch(e => …)Re: TypeScript is surprisingly ok for compilers
#23Earlier quoted context omitted.
He's talking about compilers for small languages. The Typescript LSP works fine on very big projects like VSCode so I think you'd need an enormous language like C++ or Rust before you'd run into those limits. But still, I think I'd rather use Rust. I'm pretty sure the code would be nicer (e.g. no need for the explicit tag field or for the visitor hack).
I see ‘TS server has been restarted 5 times in 5 minutes’ daily.
Re: TypeScript is surprisingly ok for compilers
#24 export const run = (f: () => T): T => f();
Now you can go: const inferred_type = run(() => {
switch(blah) {
...
}
})Re: TypeScript is surprisingly ok for compilers
#25Is that really suprising? Typescript is yet another language that has, kicking and screaming, picked up most of the ML featureset. I'd expect it to be, well, fine; the lack of real pattern matching is a pain, so it's going to be inferior to OCaml, but fine, no different from using C# or Swift or Dart or Kotlin or something of that ilk.
The biggest expressivity pain point in practice for me is try/catch not being an expression, so I can’t do const c = try { … }
string something = null;
try {
something = mayThrow();
} catch (SomeException ex) {
log.Info(ex);
} catch (Exception ex) {
log.Fatal(ex);
throw;
}
if (something != null) {
...
}
Would be actually nice if it had F#'s try...with https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref... and would allow us something like: var something = try {
mayThrow()
} with (SomeException ex) {
log.Info(ex);
} with (Exception ex) {
log.Fatal(ex);
throw;
}
Or some way to do pattern matching on exceptions for switch expression. var something = mayThrow() switch {
(SomeException ex) => {
log.Info(ex);
return null;
}
(Exception ex) => {
log.Fatal(ex);
throw;
}
var passThru => passThru
}Re: TypeScript is surprisingly ok for compilers
#26TS's type system is fun but a part of me always wonders how much faster TS's compiler would be if it was written in a compiled language (assuming "good implementation", which is a big assumption!)
Also tsc is slow, sure, but only for the first run. Enabling `incremental` flag or using watch mode with `--transpile-only` usually brings compile time under 100ms, Making it practically indistinguishable from SWC or ESBuild.
Re: TypeScript is surprisingly ok for compilers
#27Is that really suprising? Typescript is yet another language that has, kicking and screaming, picked up most of the ML featureset. I'd expect it to be, well, fine; the lack of real pattern matching is a pain, so it's going to be inferior to OCaml, but fine, no different from using C# or Swift or Dart or Kotlin or something of that ilk.
The biggest expressivity pain point in practice for me is try/catch not being an expression, so I can’t do const c = try { … }
const std = @import("std");
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
try stdout.print("Hello, {s}!\n", .{"world"});
}Re: TypeScript is surprisingly ok for compilers
#28That is surprising, I would've thought that TS would have more overhead because of the interfaces adding extra weight. Makes me wonder what else TS could apply to. Language parsing, maybe?
Re: TypeScript is surprisingly ok for compilers
#29The author uses a TypeScript subset to write a compiler to 32bit ARM assembly and explains that it almost looks like Pseudocode, so it is very accessible. A sentiment I can get behind, despite avoiding it in any case possible.
Re: TypeScript is surprisingly ok for compilers
#30Is that really suprising? Typescript is yet another language that has, kicking and screaming, picked up most of the ML featureset. I'd expect it to be, well, fine; the lack of real pattern matching is a pain, so it's going to be inferior to OCaml, but fine, no different from using C# or Swift or Dart or Kotlin or something of that ilk.
That's some very high level view - in reality even tough those languages are in similar categories the experience would be vastly different : TypeScript - powerful type system but shit underlying stdlib and language (no pattern matching/switch expressions) Dart - worse than TS because the object model is closed - so no dynamic freedom, but the type system and expressions are weaker then the rest. Also 0 meta programm…