Syntax Cache
BlogMethodFeaturesHow It WorksBuild a Game
  1. Home
  2. TypeScript
TypeScript7 topics28+ exercises

TypeScript Syntax Practice

Type-check from memory, not from red squiggles.

Short daily reps. Spaced repetition automatically brings back what you keep forgetting.

You don't need another TypeScript tutorial. You need a reference you can scan while you're writing code -- one that shows you the exact syntax for generic constraints, utility type composition, and discriminated union patterns without burying it in paragraphs of explanation.

That's what this page is. Each topic below links to a dedicated cheat sheet with copy-ready examples, inline output comments, and notes on the gotchas that trip people up. If you already understand TypeScript's type system conceptually but keep pausing to look up the syntax, you're in the right place.

The exercises complement the cheat sheets. They test whether you can write the patterns from memory -- not just recognize them. Ten minutes of daily practice turns "I think it's something like this" into automatic recall.

For a broader overview covering type narrowing, discriminated unions, and common compiler errors, see the [TypeScript concept page](/javascript/typescript).

Popular topics include TypeScript Generics: Constraints, Defaults & Patterns, TypeScript Utility Types: Partial, Pick, Omit & More, TypeScript Type Narrowing: Guards, Predicates & Patterns.

Built for TypeScript Learners

Great for
  • TypeScript developers who know the concepts but blank on exact syntax during coding.
  • Frontend and full-stack engineers using TypeScript daily who want faster recall.
  • Developers preparing for TypeScript-heavy interviews or code reviews.
  • Teams adopting TypeScript who need a shared quick-reference resource.
You'll be able to
  • Write generic constraints without trial and error.
  • Compose utility types like Partial, Pick, and Omit from memory.
  • Narrow union types confidently using typeof, in, and type predicates.
  • Know when to reach for interface vs type without second-guessing.
  • Use satisfies, template literal types, and conditional types fluently.

Practice by Topic

Pick a concept and train recall with small, focused reps.

6 exercisesGotchas included

Generics

Stop guessing at generic constraints and write type-safe reusable code on the first try.

Show 3 gotchasHide gotchas
  • Constraints use extends, not implements: <T extends HasLength>.
  • Default type parameters go after required ones: <T, U = string>.
  • The keyof + extends pattern is the most common generic pattern in real codebases.
Learn more
5 exercisesGotchas included

Utility Types

Compose Partial, Pick, Omit, and Record without looking them up every time.

Show 3 gotchasHide gotchas
  • Partial<T> makes ALL properties optional, not just some -- use Pick + Partial for selective optionality.
  • Omit<T, K> doesn't error on invalid keys -- you can omit keys that don't exist.
  • Record<K, V> creates an index signature, not a fixed-key object.
Learn more
5 exercisesGotchas included

Type Narrowing

Narrow broad types to specific ones without resorting to type assertions.

Show 3 gotchasHide gotchas
  • typeof null is "object" -- always check for null separately.
  • Closures don't narrow: reassigning a variable inside a callback resets narrowing.
  • Custom type guards (x is T) are the only way to narrow with complex logic.
Learn more
6 exercisesGotchas included

Interfaces vs Types

Pick the right tool for the job -- interface for extendable objects, type for everything else.

Show 3 gotchasHide gotchas
  • Only interface supports declaration merging (adding fields across files).
  • Only type can represent unions, tuples, and mapped types.
  • For plain object shapes, either works -- consistency matters more than the choice.
Learn more
6 exercisesGotchas included

Union & Intersection

Build precise types with union and intersection operators without losing type safety.

Show 3 gotchasHide gotchas
  • Union (|) means "one of these." Intersection (&) means "all of these."
  • Discriminated unions need a shared literal property for narrowing to work.
  • Exhaustive checking with never catches missing cases at compile time.
Learn more
0 exercisesGotchas included

Template Literal Types

Generate string union types dynamically from other types -- no manual duplication.

Show 3 gotchasHide gotchas
  • Template literal types produce union combinations: 2 x 3 base types = 6 output types.
  • Built-in Uppercase, Lowercase, Capitalize, Uncapitalize only work at the type level.
  • Complex template literals can slow down the compiler -- keep unions small.
Learn more
0 exercisesGotchas included

satisfies Operator

Validate object shapes without losing precise inferred types.

Show 3 gotchasHide gotchas
  • satisfies checks the type without widening -- as overrides the type entirely.
  • Works best with Record and config objects where you want literal key types preserved.
  • Available since TypeScript 4.9 -- check your project's TS version.
Learn more

TypeScript Cheat Sheets

Copy-ready syntax references for quick lookup

GenericsUtility TypesType NarrowingInterfaces vs TypesUnion & Intersection TypesTemplate Literal Typessatisfies Operator

Sample Exercises

Example 1Difficulty: 1/5

Write a generic identity function that takes type T and returns T

function identity<T>(x: T): T { return x; }
Example 2Difficulty: 1/5

Make all User properties optional for an update payload

Partial<User>

Done Googling TypeScript syntax?

Ten minutes a day. No setup. The syntax sticks.

Why this works

TypeScript's type system has dozens of utility types, narrowing techniques, and generic patterns. You won't use all of them every day, which means the less common ones fade fast. Spaced repetition keeps the full toolkit fresh so you don't relearn Record syntax every time you need it.

FAQ

How is this different from the TypeScript handbook?

The handbook teaches concepts. These cheat sheets are scannable references you use while coding. No long prose blocks -- just syntax, output comments, and gotcha notes. The exercises test recall so the patterns stick without re-reading docs.

Do I need to know TypeScript basics first?

Yes. This content assumes you understand what types, interfaces, and generics are. It's for developers who get the concepts but keep forgetting the exact syntax -- not for learning TypeScript from scratch.

I already use TypeScript daily. Why would I practice it?

Daily usage reinforces the patterns you use often. It doesn't help with the ones you use occasionally -- generic defaults, conditional types, template literal patterns. Those are exactly what spaced repetition targets.

Are the exercises TypeScript-specific?

Yes. Every exercise uses TypeScript syntax with type annotations, generics, and utility types. They're graded on TypeScript-specific constructs, not just JavaScript logic.

What TypeScript version do the cheat sheets cover?

Content covers TypeScript 5.x features including the satisfies operator (4.9+), const type parameters (5.0+), and current utility type behavior. Examples use modern syntax throughout.

Try it. It takes two minutes.

Free daily exercises with spaced repetition. No credit card required.

Syntax Cache

Build syntax muscle memory with spaced repetition.

Product

  • Pricing
  • Our Method
  • Daily Practice
  • Design Patterns
  • Interview Prep

Resources

  • Blog
  • Compare
  • Cheat Sheets
  • Vibe Coding
  • Muscle Memory

Languages

  • Python
  • JavaScript
  • TypeScript
  • Rust
  • SQL
  • GDScript

Legal

  • Terms
  • Privacy
  • Contact

© 2026 Syntax Cache

Cancel anytime in 2 clicks. Keep access until the end of your billing period.

No refunds for partial billing periods.