News for hackers. Stuff that matters.
Re:I’m porting the TypeScript type checker tsc to Go by forty on Tuesday January 25, 2022 @01:10PM (#30075512)
go means it's going to be easier to integrate to esbuild :)

I'm happy to see this, as honestly I don't really understand why you would compile TS without type checking.

Re:I’m porting the TypeScript type checker tsc to Go by eatonphil on Tuesday January 25, 2022 @01:13PM (#30075560)
> I'm happy to see this, as honestly I don't really understand why you would compile TS without type checking.

I don't think I'm remotely alone in doing this but I'll share from my perspective. I have two modes while writing TypeScript stuff: 1) prototyping something where I don't want to spend time writing types (or maybe I write some types but I don't care if they are correct or line up yet) but I still want to have JavaScript generated so I can test the thing out manually and 2) getting types correct as part of long-term maintenance and edge-case removal.

There are fast TypeScript -> JavaScript generators today like swc and esbuild. tsc is not fast. So I can speed up "1)" from above if I use swc and esbuild and only use tsc for "2)" from above.

As people write faster implementations of tsc-the-type-checker though I'll be happy to use that instead and just not use tsc anymore.

Re:I’m porting the TypeScript type checker tsc to Go by m-hilgendorf on Tuesday January 25, 2022 @01:25PM (#30075779)
> 1) prototyping something where I don't want to spend time writing types

It doesn't compile to JS, but this is one of the canonical use cases for Stanza 's (1) "optional" type system

(1) http://lbstanza.org/optional_typing.html

Re:I’m porting the TypeScript type checker tsc to Go by mixedCase on Tuesday January 25, 2022 @03:09PM (#30077340)
Have you tried doing Type-Driven Development? IME, most of the time constraints are determined through types first with the code being done later tends to replace the game of "what kind of complex and non-obvious types fit my code the most" with a "oh, the implementation is obvious" reaction.

It also makes it easier to determine what behavior is worth testing and which ones are already covered by your types, if you tend to write tests last. If instead you're used to Test-Driven Development you can do types->tests->code.

Re:I’m porting the TypeScript type checker tsc to Go by eatonphil on Tuesday January 25, 2022 @03:15PM (#30077432)
I've spent a lot of time programming in Standard ML and yeah that's a prerequisite there.

But no I don't prefer it to what I do in TypeScript.

Re:I’m porting the TypeScript type checker tsc to Go by tshaddox on Tuesday January 25, 2022 @01:41PM (#30076011)
Out of curiosity, how often do you have a project in the first mode that gets large enough that the speed of compiling TS to JS is significant?
Re:I’m porting the TypeScript type checker tsc to Go by nicoburns on Tuesday January 25, 2022 @01:48PM (#30076137)
If you're writing UI code then even a few seconds is slow. You don't want to be waiting 5 seconds every time you move something a couple of pixels to the left.
Re:I’m porting the TypeScript type checker tsc to Go by eatonphil on Tuesday January 25, 2022 @01:43PM (#30076031)
There is a huge difference even in small and mid-size projects.

https://datastation.multiprocess.io/blog/2021-11-13-benchmar...

Re:I’m porting the TypeScript type checker tsc to Go by forty on Tuesday January 25, 2022 @02:16PM (#30076577)
That makes sense, I would generally use JS directly for mode 1), but I understand the use case.
Re:I’m porting the TypeScript type checker tsc to Go by mattkrick on Tuesday January 25, 2022 @01:46PM (#30076094)
Personally, I let vscode do typechecking on open files & have a pre-commit git hook to typecheck changed files.

When it comes to starting up a development server & building the client, there's a huge cost to repeatedly typechecking the same 1000+ files. By cutting out typechecking & only compiling, I can reduce the webpack client build from 40 seconds to 3 seconds (using sucrase).

Re:I’m porting the TypeScript type checker tsc to Go by forty on Tuesday January 25, 2022 @02:07PM (#30076461)
I'm answering to you but this is really for most siblings:

I maintain a fairly large TS code base (nodejs backend). I think a full rebuild is 1:30 on my relatively recent laptop (i7-8650U, lots of RAM). But in practice I always use tsc -w and compile is mostly instant after editing a file (I do have to wait whenever I launch the command after I boot, but after that, it's fast enough).

tsc now support incremental compilation too, though I haven't played with it too much as I'm happy with watch mode.

Re:I’m porting the TypeScript type checker tsc to Go by rezonant on Tuesday January 25, 2022 @02:32PM (#30076814)
Incremental compilation is _okay_ but it seems to perform full rebuilds if the previous build is _too_ old which is weird- meaning that more builds than expected take the entire time to complete. Nonetheless I use it for all of my builds. On the other hand this may just be because of the spiraling nature of type inference, where TS needs to re-examine a large amount of the program from a change that appears simple.

Personally I only have a small number of projects that take more than 10-20 seconds to compile, but those ones are painful. I should probably do the same with -w for those.

Re:I’m porting the TypeScript type checker tsc to Go by morelisp on Tuesday January 25, 2022 @02:36PM (#30076858)
What if not everyone else on your team is paying attention to their editor's warnings? What if the LS's async response doesn't come fast enough? What if, god forbid, you have to change something on a different computer?

If it's not in your CI/CD scripts, it's not actually getting checked.

> I can reduce the webpack client build... to 3 seconds

This is about 10x longer than any interaction with a computer should be.

Re:I’m porting the TypeScript type checker tsc to Go by chakkepolja on Wednesday January 26, 2022 @02:37AM (#30082847)
> If it's not in your CI/CD scripts, it's not actually getting checked.

You can make a similar argument and say you must write in a sound type system language, and TS typesystem is unsound.

Re:I’m porting the TypeScript type checker tsc to Go by morelisp on Wednesday January 26, 2022 @07:05AM (#30084540)
Sorry, I don't understand the analogy. Yes, TS allows some bugs through, and that's a problem too. But that's also a far cry from "always rely on humans to run complex processes in a consistent way."
Re:I’m porting the TypeScript type checker tsc to Go by tdfirth on Tuesday January 25, 2022 @02:37PM (#30076876)
This is similar to what I do (although I use esbuild), however like an idiot I just run tsc manually so obviously I forget sometimes and it takes 10 minutes to realise the build failed.

Not great... I'm ashamed but it's just me on this project atm.

edit: misread parent originally

Re:I’m porting the TypeScript type checker tsc to Go by bastawhiz on Tuesday January 25, 2022 @01:47PM (#30076117)
If it takes one minute to type check a codebase and ten seconds to compile it to JavaScript, then whenever I simply need to produce a JavaScript file without type checking I'll save myself the fifty seconds. If my editor's TS language server does the checking and my bundler is just compiling for my dev environment, I don't want both tools duplicating each other's work.
Re:I’m porting the TypeScript type checker tsc to Go by forty on Tuesday January 25, 2022 @02:23PM (#30076691)
Answering to myself, a colleague suggestion (from tsc doc actually): use tsc --noEmit (for type checking) and a fast compiler.

tsc --noEmit duration is 2/3 of a normal build on our fairly large code base, so that can definitely speeds things up (for CI for example)

Re:I’m porting the TypeScript type checker tsc to Go by apazzolini on Tuesday January 25, 2022 @01:18PM (#30075663)
We use SWC with ts-node to strip types in dev for faster iteration loops and run the full tsc typechecker in CI (and optionally as a separate process on your local machine).
Re:I’m porting the TypeScript type checker tsc to Go by postalrat on Tuesday January 25, 2022 @01:30PM (#30075869)
You compile ts without type checking when the options to do so are 10x+ faster than with type checking.
Re:I’m porting the TypeScript type checker tsc to Go by pjmlp on Tuesday January 25, 2022 @01:47PM (#30076125)
I really don't get this, when I save my TS files they are already compiled into JS on the fly, ready to fed into a <script />.
Re:I’m porting the TypeScript type checker tsc to Go by recursive on Tuesday January 25, 2022 @02:15PM (#30076563)
By what? What if they were updated from an upstream repo, and never saved from an editor? What if you change branches without an upstream repo?
Re:I’m porting the TypeScript type checker tsc to Go by pjmlp on Tuesday January 25, 2022 @02:49PM (#30077058)
By VS and VSCode, the IDE/editor that belongs to the same company that does TypesScript.

If I really need to call tsc explicitly, the few seconds that I have to wait, versus the minutes on some other languages, won't make me lose sleep over it.