true +  // returns "true"
true +  //error TS2365: Operator '+' cannot be applied to types 'true' and 'never'.
You put a job post up on Hacker News and within 24 hours TypeScript's resume comes into your inbox. They have a decent cover letter, so you call them for a phone screen. This candidate stood out to you because they said they will deliver error messages in your text editor as you write your programs. You invite TypeScript in for an onsite.
During the onsite, TypeScript does a whole presentation about how your code will get type checked before it runs. But, you still have a lot of questions about how exactly everything works.
You say, "Hey, let's walk through this. I know that this is how my code gets compiled now..."
You grab a marker and write on the board:
- AST is converted to bytecode.
- Bytecode gets fed into another program called runtime, and this is when code gets evaluated.
- TypeScript source code is compiled into a TypeScript AST
- TypeScript AST is type checked
- Bytecode is evaluated at runtime.
TypeScript sometimes refers to themselves in third person. :D
Things are going great and everything seems to be moving along nicely. You decide to dig deeper and ask some tougher questions.
You ask, "Are you dynamically typed or statically typed?
To which TypeScript replies, "I'm not entirely one or the other. You can use type annotation to define types or you can simply leave them out and I'll do my best to infer the type. I'm at my best when I know the type of everything in the program at compile time, but I can still compile everything if I don't have all of that information.
You follow up, by asking, "If we migrate to you, do we have move everything to TypeScript at once in order for our code to work?"
After a short pause TypeScript says, "Look, I'm going to be upfront and tell you that it needs to be fixed when your code is type checked by the compiler. Some people might say I'm a bit of a complainer, but I just call things how I see 'em."
You are a bit put off by the arrogance, but you thank them for their transparency anyways. Next, you transition back to more "soft skills" by asking about how they communicate errors once they find them.
To which they reply, "Well, if you have a halfway decent text editor, you're going to see some of those red squiggly lines under places where you need to make changes. This goes back to how I type check at compile time, which gives you syntax and type errors at compile instead of at runtime."
TypeScript, you're hired!
Sources: Programming TypeScript, May 2019. Boris Cherny. Chapter 2. TypeScript: A 10_000 Foot View