Read this blog post if you are a JavaScript programmer and want to get a rough idea of what using TypeScript is like (think first step before learning more details). You’ll get answers to the following questions:
Note: This blog post does not explain why TypeScript is useful. If you want to know more about that, you can read my TypeScript sales pitch.
node --watch
Now that Node.js has built-in support for TypeScript, we can use it as the foundation of simple playgrounds that let us interactively explore TypeScript code.
In this blog post, we explore how we can test that complicated TypeScript types work as expected. To do that, we need assertions at the type level and other tools.
The TypeScript handbook makes an interesting statement: “Often, the checks in a conditional type will provide us with some new information. Just like narrowing with type guards can give us a more specific type, the true branch of a conditional type will further constrain generics by the type we check against.”
In this blog post, we’ll see that this goes further than you may think.
never
in TypeScriptIn this blog post, we look at the special TypeScript type never
which, roughly, is the type of things that never happen. As we’ll see, it has a surprising number of applications.
T[]
vs. Array<T>
in TypeScriptIn this blog post, we explore two equivalent notations for Arrays in TypeScript: T[]
and Array<T>
. I prefer the latter and will explain why.
In this blog post, we examine how TypeScript handles JavaScript symbols at the type level.
If you want to refresh your knowledge of JavaScript symbols, you can check out chapter “Symbols” of “Exploring JavaScript”.
A conditional type in TypeScript is an if-then-else expression: Its result is either one of two branches – which one depends on a condition. That is especially useful in generic types. Conditional types are also an essential tool for working with union types because they let us “loop” over them. Read on if you want to know how all of that works.
A mapped type is a loop over keys that produces an object or tuple type and looks as follows:
{[PropKey in PropKeyUnion]: PropValue}
In this blog post, we examine how mapped types work and see examples of using them. Their most importing use cases are transforming objects and mapping tuples.
infer
In this blog post, we explore how we can extract parts of compound types via the infer
keyword.
It helps if you are loosely familiar with conditional types. You can check out chapter “Conditional types” in “Exploring TypeScript” to read up on them.