QuizBytesDaily← All quizzes
HomeQuizTypeScript
📘

TypeScript Quiz Questions

Level up from basic types to advanced TypeScript patterns

Take TypeScript Quizzes →

About TypeScript Quizzes

TypeScript adds a powerful static type system to JavaScript, catching entire categories of runtime errors at compile time. But TypeScript's type system goes far beyond simple type annotations — it includes generics, conditional types, mapped types, template literal types, and inferred types that can express complex type relationships that JavaScript cannot.

QuizBytesDaily's TypeScript quizzes help you understand not just the syntax but the semantics of TypeScript's type system. Why does `unknown` require a type narrowing check but `any` doesn't? What's the difference between `interface` and `type` alias? How do you write a generic function that preserves the literal type of its argument? When should you use `as const`?

We cover practical TypeScript patterns used in real codebases: discriminated unions for exhaustive switch statements, utility types (`Partial`, `Pick`, `Omit`, `ReturnType`, `Awaited`), the `satisfies` operator, strict null checks, module augmentation, and the `infer` keyword for conditional type inference. These are the patterns that separate TypeScript users from TypeScript engineers.

Why Learn TypeScript?

Industry standard
TypeScript is now the default choice for new JavaScript projects at most companies. Fluency in advanced TypeScript types is increasingly a hiring differentiator.
Write self-documenting code
Well-typed TypeScript code is documentation. Clear types reduce the need for comments and make code reviews faster.
Catch bugs before they ship
TypeScript's strict mode, combined with advanced utility types, catches entire classes of null-pointer, type-mismatch, and refactoring bugs before runtime.

What You'll Find in Our TypeScript Quizzes

  • Structural vs. nominal typing and type compatibility
  • Generics: constraints, defaults, and higher-kinded patterns
  • Utility types: Partial, Required, Pick, Omit, Record, Extract, Exclude
  • Conditional types and the `infer` keyword
  • Mapped types and template literal types
  • Discriminated unions and exhaustive type checking
  • Strict mode flags and their practical implications
Sponsored

Other Quiz Categories

🐍 Python🤖 AI & Machine Learning🧮 Algorithms JavaScript🏗️ System Design

Sample TypeScript Quiz Questions

A taste of what you'll find in the TypeScript quiz series.

1

What is the difference between `unknown` and `any` in TypeScript?

A.There is no difference — they are aliases
B.`unknown` disables all type checking; `any` requires a type guard before use
C.`unknown` requires a type guard or narrowing before use; `any` bypasses all type checks✓ Correct
D.`unknown` is for primitive types only; `any` works with all types

Explanation: `any` is a TypeScript escape hatch — you can assign anything to it and use it as anything, but you lose all type safety. `unknown` is the type-safe alternative: you can assign any value to `unknown`, but you cannot call methods, access properties, or pass it where a specific type is expected without first narrowing it with a type guard (typeof, instanceof, or a custom predicate). Prefer `unknown` over `any` whenever you genuinely don't know the type.

2

What does the `Partial<T>` utility type do in TypeScript?

A.Removes all properties from type T
B.Makes all properties of type T required and non-nullable
C.Makes all properties of type T optional (adds ? to each property)✓ Correct
D.Picks only the optional properties from type T

Explanation: `Partial<T>` constructs a new type with all properties of T set to optional. It is equivalent to `{ [K in keyof T]?: T[K] }`. This is useful for update/patch functions where you only want to accept a subset of fields: `function updateUser(id: string, patch: Partial<User>)`. The counterpart is `Required<T>`, which makes all properties non-optional.

3

What is a discriminated union in TypeScript and what makes it useful?

A.A union type where all members share a common literal property used to narrow the type✓ Correct
B.A union of types that can only contain primitive values
C.A union where TypeScript automatically selects the most specific type
D.A union type where only one member can be assigned at a time

Explanation: A discriminated union (also called a tagged union) is a union where each member has a shared property with a unique literal value — the discriminant. For example: `type Shape = { kind: 'circle'; radius: number } | { kind: 'square'; side: number }`. TypeScript uses the `kind` property to narrow the type in a switch statement, and with `strictNullChecks` enabled, the compiler will warn you if you add a new union member but forget to handle it in a switch — enabling exhaustive type checking.

Sponsored

Ready to test your TypeScript knowledge?

Free daily quizzes — no signup, no account, no cost.

Start TypeScript Quizzes →