Tutorials
Practical tutorials for the work we actually do. Pick one, read it in order, and apply it.
Flatten nested ifs with early returns, let a switch tell you when you forgot a case, and use a lookup object for word-to-text mappings. After this, a new status cannot slip through.
Replace a data-or-error object with a union tagged by success, then add a generic Outcome and an unwrap helper. After this, the compiler knows which property exists in each case.
Compare import type, the inline type keyword and a plain import, and see which ones leave code in the compiled file. After this, a types-only import cannot load a module with side effects.
Read a long assignability error from the bottom, then fix the usual causes: a wrong value, a wrong type and a literal widened to string. After this, a nested mismatch points to one property.
Turn two any-typed helpers into generic functions and see what the compiler now catches. After this, a typo or a wrong method on the result is a compile error.
Reproduce the missing declaration error, check whether the library has its own types, install the @types package and prove the types work. After this, you know the fallback when no types package exists.
Derive a draft type with Partial, require every field with Required, and write one check that turns a draft into the finished type. After this, an unfinished form cannot reach the submit function.
Derive a public type from User with Omit and a short card type with Pick, then close the gap where Omit accepts a misspelled key. After this, one change to User updates every smaller type.
Run the same class with the private keyword and with a hash field, and compare the output, the errors and what outside code can still reach. After this, you can pick one and say why.
Key a lookup table by an enum or a union of literals so a missing or misspelled key is a compile error. After this, adding a status shows you every table that needs an entry.
Replace scattered casts with one assertion function and one typed fetch helper. After this, a 404 or a changed payload fails with a clear message instead of carrying a wrong type.
Receive a nested payload as unknown and narrow it with two small helpers until every property is checked. After this, you can write a parser that rejects wrong data and returns a real type.