W3Reference.com
Toggle Menu
Home
Online Rust Compiler
Tutorials
Python Tutorial
Java Tutorial
Rust Tutorial
TypeScript Tutorial
ReactJS Tutorial
HTML & CSS Basics
Docker Containers Guide
Kubernetes Tutorial
Software Design Patterns
Blog
All Posts
Advanced TypeScript Techniques
Test your skills in decorators,type inference,and advanced type manipulation.
1. Which utility type creates a new type with all properties of T set to optional?
Partial<T>
Required<T>
Readonly<T>
Pick<T, K>
2. Which of the following are examples of mapped types in TypeScript?
Readonly<T>
Partial<T>
Exclude<T, U>
Record<K, T>
3. Conditional types in TypeScript can depend on type relationships to produce different types.
True
False
4. What is the conventional single-letter name for a generic type parameter in TypeScript (e.g., in `function identity<T>(arg: T): T`)?
5. Which utility type constructs a new type by omitting specified properties K from type T?
Omit<T, K>
Exclude<T, U>
Pick<T, K>
Partial<T>
6. Which of the following are valid type guard functions in TypeScript?
A function returning `x is string`
A function returning `boolean` without a type predicate
A function using `typeof x === 'number'` with a `x is number` predicate
A function using `as` to assert a type
7. Interfaces can be merged by declaring them multiple times, but type aliases cannot.
True
False
8. What is the resulting type of `type Result = ReturnType<() => number>`?
9. What does the `readonly` modifier do in a mapped type like `{ readonly [P in keyof T]: T[P] }`?
Makes properties read-only
Makes properties optional
Removes properties
Adds new properties
10. Which utility types transform the types of properties in an existing type?
ReturnType<T>
Readonly<T>
Partial<T>
Parameters<T>
11. The `unknown` type is a stricter alternative to `any` because it requires type checking before use.
True
False
12. What term describes a type that can be one of several types, denoted with the `|` operator (e.g., `string | number`)?
13. Which operator is used to get the union of keys from an object type T?
keyof T
keys<T>
T.keys
Object.keys(T)
14. Which keyword is used to enforce that a generic type parameter must extend another type (e.g., `function f<T extends string>(arg: T)`)?
extends
implements
requires
restrict
15. Which of the following are considered advanced generic techniques in TypeScript?
Generic constraints with `extends`
Default generic parameters
Conditional types with generics
Type inference with `infer` in generics
Reset
Answered 0 of 0 — 0 correct