TypeScript Tutorials
Focused TypeScript tutorials for practical type-safety problems: writing .d.ts declaration files for JavaScript helpers, narrowing union responses safely, catching any leaks under strict mode, and diagnosing slow tsc builds.
Each article gives you a minimal, compilable example with exact tsc diagnostics so you can test the fix in seconds.
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.
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.
Derive a draft type with Partial, require every field with Required, and write one check that turns a draft into the finished type.
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.
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.
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.
Install typescript-eslint on TypeScript 7, switch the rules on as warnings, count them by rule and hold the count down.
Add a user property to the Express request type with a module augmentation in one declaration file.
Add a brand to two string ids and a parse function that creates them. After this, passing an orderId where a userId is expected is an error in the editor.