---
title: "TypeScript Advanced: Types, Generics, Utility Types"
description: "Master TypeScript: advanced types, generics, utility types, decorators, and type-safe patterns for scalable codebases."
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/quizzes/post/typescript-advanced-quiz
---

# TypeScript Advanced: Types, Generics, Utility Types

Welcome to the TypeScript Advanced Quiz! Test your knowledge on advanced types, generics, utility types, and more. Each question has a hint and explanations for all options. Good luck!

## Questions

### 1. What is an interface in TypeScript?

- A syntax to define the shape of an object, including properties and methods
- A runtime construct used to instantiate objects with private internal state
- A type alias that creates a unique nominal identity for primitive values
- A class-only decorator used to inject metadata into the constructor

**Hint:** Think about contracts.

### 2. What is a union type?

- A type allowing a variable to hold values from one of several distinct types
- A type that combines multiple object shapes into a single required structure
- A specialized array type that can only hold a specific sequence of primitives
- A dynamic type that bypasses the compiler checks to allow any value

**Hint:** Think about multiple possibilities.

### 3. What is an intersection type?

- A type that combines multiple existing types into one, requiring all properties
- A type that allows choosing between one of two distinct object definitions
- A type guard that checks if an object belongs to a specific class instance
- A utility type used to remove specific keys from an existing interface

**Hint:** Think about combining types.

### 4. What is a generic in TypeScript?

- A way to create reusable components that work with a variety of types
- A global type that automatically converts strings into numeric values
- A naming convention for variables that do not have a defined data structure
- A tool for generating random data for unit tests and documentation

**Hint:** Think about reusable with types.

### 5. What is a generic constraint?

- A rule using the "extends" keyword to limit the types a generic can accept
- A runtime check that throws an error if a generic type is incorrectly cast
- A method for preventing a generic class from being inherited by others
- A syntax for forcing a generic to only accept nullable or undefined values

**Hint:** Think about restricting generics.

### 6. What is a conditional type?

- A type that selects one of two types based on a ternary-like condition
- A runtime conditional statement used to validate user input types
- A type alias that can only be accessed if a specific flag is set in tsconfig
- A function that returns a different type based on the value of its arguments

**Hint:** Think about type-level if-else.

### 7. What is a mapped type?

- A way to create a new type by iterating through the keys of an existing type
- An array transformation that changes the data types of every stored element
- A specialized dictionary type that only accepts string-based coordinate keys
- A compilation step that maps TypeScript source files to JavaScript files

**Hint:** Think about transforming type properties.

### 8. What is the Partial utility type?

- A utility that constructs a type with all properties of T set to optional
- A utility that removes the first half of the properties from a given object
- A type that allows an object to only implement the methods of an interface
- A tool for splitting a single type definition across multiple source files

**Hint:** Think about optional properties.

### 9. What is the Readonly utility type?

- A utility that constructs a type with all properties of T set to readonly
- A type that prevents a variable from being reassigned to a different reference
- A compiler flag that prevents any changes to the project source code
- A specialized interface used for reading data from external JSON files

**Hint:** Think about immutability.

### 10. What is the Pick utility type?

- A utility that creates a type by selecting a specific set of keys from T
- A tool for randomly selecting a single property from a union type
- A function that extracts a value from an object using a string key
- A utility that removes the specified keys from an object type T

**Hint:** Think about selecting properties.

### 11. What is the Omit utility type?

- A utility that creates a type by picking all properties from T and then removing K
- A tool for ignoring type errors in a specific block of TypeScript code
- A utility that converts all mandatory properties into optional properties
- A syntax used to exclude a specific file from the compilation process

**Hint:** Think about excluding properties.

### 12. What is the Record utility type?

- A utility used to construct an object type with specific keys and a specific value type
- A persistent data structure that saves type information into a database
- A type that logs every change made to an object during runtime execution
- A utility that converts an object into an array of its key-value pairs

**Hint:** Think about key-value mapping.

### 13. What is the typeof operator in TypeScript?

- An operator used in a type context to extract the type of a variable or property
- A runtime function that returns a string representing the primitive data type
- A type guard that checks if a class implements a specific interface
- A keyword used to define a new type based on an existing JavaScript class

**Hint:** Think about extracting types.

### 14. What is the keyof operator in TypeScript?

- An operator that produces a union of string or numeric literal keys from an object
- A runtime method for retrieving an array of all keys present in an object
- A utility for checking if a specific key exists within a JSON configuration
- A keyword used to access private properties in an inherited TypeScript class

**Hint:** Get property names as type?

### 15. What is the Exclude utility type?

- A utility that removes types from a union that are assignable to a second type
- A utility that removes all null and undefined values from a given type
- A keyword used to prevent a specific file from being imported into a module
- A utility that deletes specific properties from an object interface

**Hint:** Remove types from union?

### 16. What is the Extract utility type?

- A utility that selects members of a union that are assignable to a second type
- A tool for pulling the documentation comments out of a TypeScript file
- A utility that retrieves the first element from a tuple or array type
- A method for copying the properties of one class into another class

**Hint:** Keep matching union members?

### 17. What is the NonNullable utility type?

- A utility that constructs a type by excluding null and undefined from T
- A compiler setting that throws an error if a variable is assigned a null value
- A type that forces a variable to always have a default numeric value
- A runtime check that ensures a database response is not empty

**Hint:** Remove null and undefined?

### 18. What is the Parameters utility type?

- A utility that extracts the types of arguments from a function type as a tuple
- A utility that generates a list of all variables declared within a function
- A keyword used to define the maximum number of arguments a function can take
- A utility that extracts the return type of a given function definition

**Hint:** Extract function parameters?

### 19. What is the ReturnType utility type?

- A utility that extracts the return type of a function type T
- A tool that automatically writes return statements for empty functions
- A utility that converts a synchronous function type into an asynchronous one
- A type that enforces a function must always return a string literal

**Hint:** Extract function return type?

### 20. What is the InstanceType utility type?

- A utility that extracts the instance type from a constructor function type
- A utility that returns the name of a class as a string literal type
- A check that confirms if a specific object is an instance of a class
- A utility that creates a new instance of a class using default parameters

**Hint:** Get instance from constructor?

### 21. What is the infer keyword in TypeScript?

- A keyword used within a conditional type to declare a type variable to be extracted
- A compiler hint that allows TypeScript to guess the type of a variable
- A syntax used to cast a value to a different type without validation
- A keyword that forces the compiler to ignore a specific type mismatch

**Hint:** Extract types within conditionals?

### 22. What is a template literal type?

- A type that uses template literal syntax to build new string types
- A JavaScript string that contains embedded expressions for runtime evaluation
- A specialized type used to define the layout of an HTML template
- A utility that converts complex objects into formatted JSON strings

**Hint:** String manipulation at type level?

### 23. What is a const assertion (as const)?

- A suffix that tells the compiler to treat a literal as its most specific type
- A keyword used to declare a variable that cannot be changed at runtime
- A method for freezing a JavaScript object to prevent property additions
- A tool for converting a dynamic array into a fixed-length linked list

**Hint:** Freeze literal types?

### 24. What is the satisfies operator in TypeScript?

- An operator used to validate a value matches a type while preserving its narrowest type
- A legacy operator replaced by the "as" keyword in modern versions
- A runtime check that confirms a variable satisfies a specific interface
- A method for ensuring that a generic type always has a default value

**Hint:** Validate type without losing inference?

### 25. What are recursive types in TypeScript?

- Types that refer to themselves in their own definition to describe nested structures
- Functions that call themselves until they reach a base condition
- A type alias that causes the compiler to enter an infinite loop
- A system for automatically generating types from circular JSON data

**Hint:** Self-referential type definitions?

### 26. What is a discriminated union?

- A union of types that share a common literal property used for narrowing
- A collection of types that are not allowed to be used in the same module
- An intersection of types that requires every property to be unique
- A list of deprecated types that are excluded from the final build

**Hint:** Pattern matching on shared property?

### 27. What is a user-defined type guard?

- A function that uses a type predicate to narrow a type within a conditional block
- A configuration setting in tsconfig that restricts the use of the "any" type
- A private method used to protect a class property from external access
- A runtime middleware that blocks invalid API requests before they reach code

**Hint:** Custom type narrowing function?

### 28. What is declaration merging in TypeScript?

- The ability for the compiler to join multiple declarations with the same name
- A naming conflict that prevents the project from being compiled
- The process of minifying multiple TypeScript files into one JavaScript file
- A tool for combining two different versions of the TypeScript compiler

**Hint:** Combine multiple declarations?

### 29. What is module augmentation?

- A way to add new type definitions to an existing external module
- An automated process that increases the performance of imported modules
- A security feature that prevents modules from being modified at runtime
- A method for importing multiple modules using a single wildcard character

**Hint:** Extend library types without modifying source?

### 30. What is the Awaited utility type?

- A utility that recursively unwraps a type to retrieve the non-promise result
- A keyword used to pause the execution of a function until a promise resolves
- A type that forces a function to always return a pending Promise
- A utility that limits how long a compiler will wait for type resolution

**Hint:** Unwrap Promise types recursively?
