Flashcards · TypeScript · Free
TypeScript flashcards, generated for you.
Example TypeScript study cards to learn from right now — then generate a full set from your own notes (plus a practice quiz) and export to Quizlet or Anki. Free, no account needed.
Example TypeScript flashcards
What is TypeScript and how does it relate to JavaScript?
TypeScript is a superset of JavaScript that adds static type checking and compiles to plain JavaScript. All valid JS is valid TS, but TS adds optional type annotations that catch errors at compile-time rather than runtime.
What is the difference between `any` and `unknown` types?
`any` disables type checking entirely—you can do anything with it. `unknown` is type-safe; you must narrow/assert the type before using it. Prefer `unknown` for maximum safety.
What does the `as const` assertion do?
`as const` tells TypeScript to treat a value as a literal type rather than a wider inferred type. For example, `const x = 'hello' as const` makes x have type `'hello'` (not `string`), and arrays become readonly tuples.
Explain the difference between `interface` and `type` alias.
Both define object shapes, but `interface` can be declaration-merged (re-declared to extend), while `type` cannot. `type` supports unions, primitives, and tuples; `interface` is limited to object shapes. Use `interface` for public APIs, `type` for flexibility.
What is a union type and how do you narrow it?
A union type like `string | number` means the value is one of multiple types. Narrow it with: `typeof` checks, `instanceof` checks, truthiness guards, or custom type guards. TypeScript then narrows the type in the conditional branch.
What does `keyof` do and what is a common gotcha?
`keyof T` returns a union of all property names of type T as literal types. Gotcha: `keyof any` evaluates to `string | number | symbol`, not the keys of a specific object. Use `keyof typeof obj` to get keys of an actual object's shape.
What is the difference between `Partial<T>` and optional properties (`?`)?
`Partial<T>` makes every property optional in a type, transforming the entire type recursively. A single optional property uses `prop?: type`. `Partial` is a utility type; `?` is a syntax modifier. Both create optional properties, but `Partial` is for bulk transformation.
Why does `null` and `undefined` behave differently, and what's the strictNullChecks gotcha?
With `strictNullChecks: true` (recommended), `null` and `undefined` are distinct types; a `string` variable cannot be `null` or `undefined` unless explicitly typed. Without it, `null` and `undefined` are assignable to any type, hiding bugs. Always enable `strictNullChecks`.
What is a generic type parameter and how does it differ from `any`?
A generic like `function id<T>(x: T): T` preserves type information—if you pass a `string`, it returns a `string`. `any` loses type safety. Generics maintain type relationships; `any` disables checking entirely. Prefer generics for type-safe reusable code.
What is the `infer` keyword and when is it used?
`infer` extracts/infers a type from a generic in conditional types. Example: `type Flatten<T> = T extends Array<infer U> ? U : T` infers the element type U from an array. Used in type utilities to conditionally extract nested types.
Make your own TypeScript study set
Flashcards for related topics
Studying TypeScript to build with AI? MindloomHQ turns it into real skills — structured courses, agent projects, and certificates.
Explore MindloomHQ →