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 the difference between 'any' and 'unknown' types in TypeScript?
'any' disables type checking entirely and allows any operation. 'unknown' is type-safe: you must narrow/assert the type before using it. Prefer 'unknown' for external data.
What does 'const' guarantee in TypeScript regarding object mutations?
'const' prevents reassignment of the variable itself, NOT mutations to the object. const obj = {x: 1}; obj.x = 2 is legal. Use 'as const' or 'readonly' for immutability.
Explain the difference between 'interface' and 'type' for object shapes.
Both define object shapes. Key differences: interfaces can be merged/extended with same name; types cannot. Types support unions/intersections more naturally. Interfaces are better for OOP; types for functional patterns.
What is 'never' type and when is it useful?
'never' represents a type with no values—for functions that never return (infinite loop, throw), unreachable code paths, or exhaustiveness checking in discriminated unions.
How do generics with 'extends' constraints work? What does 'T extends K' mean?
'T extends K' means T must be assignable to K. Example: <T extends string> restricts T to string type. Used to enforce type safety on generic parameters and enable conditional types.
What is a discriminated union and why is it powerful?
A union of types with a common literal property (the discriminant) that narrows the type. Example: type Result = {status: 'success'; data: T} | {status: 'error'; error: E}. Enables exhaustive type checking.
What is the difference between 'Partial<T>' and 'Required<T>' utility types?
'Partial<T>' makes all properties optional (?). 'Required<T>' makes all properties mandatory (removes ?). Both are shallow transformations that don't recurse into nested objects.
Explain 'keyof' operator and provide a practical example.
'keyof T' produces a union of all keys of T. Example: keyof {name: string; age: number} = 'name' | 'age'. Used for type-safe object property access functions: function pick<T, K extends keyof T>(obj: T, key: K).
What is a conditional type and how does 'infer' work?
Conditional types: T extends U ? X : Y checks if T is assignable to U. 'infer' captures a type variable in extends clause. Example: type ReturnType<F> = F extends (...args: any[]) => infer R ? R : never extracts return type.
Why might 'this' binding cause issues in TypeScript classes, and how do you fix it?
Methods lose 'this' context when passed as callbacks (common in event handlers). Solutions: use arrow function properties (this = () => {}), bind explicitly (method.bind(this)), or declare 'this: ClassName' in method signature for static type safety.
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 →