XJavascript.com
Toggle Menu
Home
Online Javascript Compiler
Tutorials
JavaScript Tutorials
TypeScript Tutorials
Blog
All Posts
TypeScript Advanced Features
Explore generics,decorators,utility types,and advanced type manipulation.
1. What is the primary purpose of generics in TypeScript?
To allow dynamic type casting
To create reusable components that work with multiple types
To replace interfaces
To enable runtime type checking
2. Which of the following are built-in TypeScript utility types? (Select all that apply)
Partial
Required
Map
Pick
Filter
3. TypeScript interfaces can be extended, but type aliases cannot.
True
False
4. What utility type constructs a type by picking the set of properties K from T?
5. Which type is used to represent values that are guaranteed to never occur?
any
unknown
never
void
6. Which of the following are valid type guards in TypeScript? (Select all that apply)
typeof x === 'string'
Array.isArray(x)
x instanceof Date
x === 'number'
x as string
7. What is the difference between 'unknown' and 'any'?
unknown is safer as it requires type checks
any is safer as it allows more operations
unknown is a subtype of any
They are functionally identical
8. Which type represents a value that could be one of several types?
Union type
Intersection type
Tuple type
Mapped type
9. What does the 'readonly' modifier do in TypeScript?
Makes a property immutable after initialization
Prevents a property from being accessed
Allows a property to be modified only in constructors
Enables runtime read-only checks
10. Which utility types transform the properties of a type? (Select all that apply)
Partial
Readonly
Exclude
ReturnType
Record
11. Mapped types create new types by transforming each property of an existing type.
True
False
12. What is the syntax for a tuple type with a string followed by a number?
13. Which feature allows you to create a type that depends on another type?
Conditional types
Union types
Index signatures
Decorators
14. What are the differences between 'type' and 'interface' in TypeScript? (Select all that apply)
Interfaces can be merged, types cannot
Types can represent primitives, interfaces cannot
Interfaces support extends, types do not
Types can use union/intersection, interfaces cannot
Interfaces are hoisted, types are not
15. Type assertions (as) change the runtime type of a value.
True
False
16. Which of the following are valid uses of tuple types? (Select all that apply)
Fixed-length arrays with specific types
Function parameters with varying types
Return types with multiple values
Union type alternatives
Mapped type keys
17. What is the purpose of a type guard function?
To throw errors for invalid types
To narrow down the type of a variable within a scope
To create new types dynamically
To enforce type checks at runtime
18. Decorators are a stage 3 proposal and require experimental flags in TypeScript.
True
False
19. What does the 'Record<K, T>' utility type create?
A union of K and T
A type with keys K and values T
A function returning T
A readonly version of K
20. Name the utility type that excludes types from a union that are assignable to another type.
Reset
Answered 0 of 0 — 0 correct