📎 Webclip
TypeScript is more than you think
TypeScript is presented as more than JavaScript with type annotations. The article splits the language into value level, type annotations, and a separate type system language, then shows that the type system has its own syntax, operators, and compile-time transformations.
Reading notes#
- The type system is described as a language in its own right, with types playing the role of values.
- Type aliases are used as variables, and type definitions are treated as single-assignment and immutable.
- The author distinguishes type system language, type annotations, and JavaScript as three levels.
- The article lists type-level operators such as assign, intersection, union, keyof, conditional types, and mapped types.
- Equality is checked by testing assignability in both directions.
- Generic types are presented as functions that run at compile time.
- Type parameters can be constrained, as in a function that only accepts array types.
- One generic type can call another, as shown with a conditional wrapper built on top of equality.
- Default type parameters are used as local aliases inside a generic definition.
- Mapped types are used for iteration over object keys and tuple indices.
- The article shows recursive conditional logic for searching nested object types.
- Mapping, filtering, and reducing are demonstrated through type transformations on objects and tuples.
- Variadic tuple types are used to merge, append, and prepend tuple elements.
- Template literal types are used for string concatenation and for joining string arrays with a separator.
- Higher-kinded types are said to be unavailable, so higher-order type functions are not supported.
- The standard library is identified with TypeScript utility types.
- The conclusion is that TypeScript’s type system can express substantial compile-time computation, even though it lacks higher-order functions.
