Cheat sheet · Foundations
TypeScript cheat sheet
Opens with creditsA working reference for developers who already write JavaScript and want TypeScript to catch real bugs, not just add annotations. It moves from everyday types through narrowing and generics to type-level tools, configuration and the boundary with untyped data.
Chapters
9 chapters · 60 concepts
1Types and the compilerWhat TypeScript is, what the compiler does with your code and the handful of types everything else is built from.7 concepts
- 1Type checking and type erasureTypeScript is JavaScript plus a static type system.
- 2Primitive and literal types
string,number,boolean,bigint,symbol,nullandundefinedare the primitive types. - 3Arrays, tuples and readonly arrays
string[](orArray<string>) is a list of any length. - 4Object types and optional propertiesAn object type lists property names and their types.
- 5
anyandunknownanyswitches type checking off for a value. - 6
neverandvoidvoidmeans a function returns nothing useful. - 7Strict null checksWith
strictNullChecks(part ofstrict),nullandundefinedare separate types that must be listed explicitly, as instring | null, and handled before…
7 in this chapterOpen this chapter2Inference and assignabilityHow TypeScript works out types you did not write, and the rules that decide whether one type fits where another is expected.7 concepts
- 1Type inferenceThe compiler infers types from values:
const n = 3is3,let n = 3isnumber, and a function's return type comes from what it returns. - 2Structural typingTypeScript compares types by shape, not by name.
- 3Excess property checksWhen you pass an object literal straight to a typed slot, extra properties the type does not declare are an error.
- 4Widening and
as constMutable bindings widen literals:let m = 'GET'isstring. - 5The
satisfiesoperatorexpr satisfies Tchecks that a value fitsTwithout changing the value's inferred type. - 6Type assertions and non-null
!value as Ttells the compiler to treat a value asT;value!says it is notnullorundefined. - 7Contextual typingWhen a function or literal is written where a type is already expected, such as a callback argument, TypeScript infers its parameter types from that context.
7 in this chapterOpen this chapter- 1Type inferenceThe compiler infers types from values:
- Unions and narrowingUnions describe values that can be one of several types; narrowing is how the compiler follows your checks to know which one you have.7 conceptsOpens with credits
- GenericsGenerics are type parameters: they let one function or type work over many types while keeping the link between input and output.6 conceptsOpens with credits
- Built-in utility typesGeneric types shipped with TypeScript that transform other types. Learn these before writing your own type-level code.6 conceptsOpens with credits
- Type-level toolsThe operators behind the utility types. They let you compute new types from existing ones, so one source of truth drives the rest.8 conceptsOpens with credits
- Interfaces, classes and enumsHow TypeScript describes object-oriented code, and the few features that are TypeScript syntax with a runtime cost.6 conceptsOpens with credits
- Modules, tsconfig and strictnessHow TypeScript files import each other, how the compiler is configured and which flags are worth turning on in every project.7 conceptsOpens with credits
- JavaScript libraries and runtime dataWhere the type system meets code and data it cannot see: untyped packages, declaration files and values that arrive at runtime.6 conceptsOpens with credits
- 10Glossary, A to ZEvery concept in the sheet and the smaller terms it uses, in one list.88 terms
About this sheet
Types, inference, narrowing, generics, type-level tools and strict configuration for real TypeScript codebases.
Related on Sefism
Picked from the other libraries by shared topics.
Roadmaps
See allBest practices
See all- TypeScript Best PracticesModern TypeScript best practices for 2026: strict settings, TypeScript 7, modeling data with unions, safe narrowing, runtime validation, generics and typed linting.
- Python Best PracticesWrite Python that stays maintainable: supported versions, pyproject and lockfiles, Ruff, type hints, errors, logging, concurrency, pytest and security.
- Secure Coding Best PracticesWrite code that resists attack: untrusted input, validation, parameterized queries, output encoding, safe parsing, uploads, SSRF and errors that fail closed.
Checklists
See all- Pull Request Checklist: Before You Open a PRA pull request checklist to run before you ask for review: scope and size, a clean diff, tests, a clear description, safe releases and a tidy branch, each with a way to verify it.
- Career Switch into Tech ChecklistMove into software from another field step by step: choose a direction, follow a learning plan, build proof of skill, use your previous domain, network, plan your runway and target a first role.
Project structures
See all- Python package and CLI project structureA command line tool published to PyPI, laid out the way the Python Packaging User Guide and uv recommend: a src layout, one pyproject.toml for metadata and every tool, a thin Typer CLI over plain, testable modules, and releases uploaded by GitHub Actions with trusted publishing. The example is mdlinks, a tool that finds broken links in Markdown files. For students who have written Python scripts and want to ship one that strangers can
pip install. - TypeScript npm library project structureA small, typed npm package (a retry helper) built the way modern libraries ship in 2026: TypeScript source in
src, bundled by tsdown intodistwith type declarations and anexportsmap, tested with Vitest, checked with publint and Are the Types Wrong, versioned with Changesets and published from CI with npm provenance. For students who want to publish their first package, and for anyone whose package works locally but breaks for users. - Flutter project structureFor anyone building one Dart app for Android, iOS and the web. The tree starts from what flutter create gives you and grows into a feature-first lib/ folder, where each feature keeps its own data, domain and presentation code, then adds tests at every level, flavors, release signing, crash reporting and, for large teams, a melos workspace of local packages.
Career questions
See all- Should I learn Python or JavaScript first?Choose based on what you want to build. JavaScript if you want web development, since it runs in every browser. Python if you are drawn to data, AI, automation or backend scripting. Both are excellent first languages, and the second one is far easier once you know the first well.
- Which programming language should I learn first?For most beginners, Python or JavaScript. Python if you lean towards data, AI, automation or want the gentlest start; JavaScript if you want to build websites and see results in a browser. The language matters much less than sticking with one long enough to build real things.
- Should I learn TypeScript or Python first in 2026?Learn Python first if you are new to programming or drawn to data and AI. Learn TypeScript first only if you already know some JavaScript or are certain about web development, and even then learn plain JavaScript for a few weeks before the types. The second language is much easier than the first.
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
- 1:1 Mentorship
- Fresh Graduate Mentorship
- Career Guidance
Brand deals, promos and partnerships: tauseeffayyaz@gmail.com