0
0
Typescriptprogramming~5 mins

Combining utility types in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the Partial<T> utility type do in TypeScript?
It makes all properties of type T optional, allowing you to create objects with some or none of the properties defined.
Click to reveal answer
beginner
How does Required<T> utility type affect a type T?
It makes all properties of T required, removing any optional modifiers from the properties.
Click to reveal answer
intermediate
What is the result of combining Partial<T> and Readonly<T> as Readonly<Partial<T>>?
You get a type where all properties of T are optional and cannot be changed after creation (read-only).
Click to reveal answer
beginner
Explain what Pick<T, K> does in TypeScript.
It creates a new type by selecting only the properties K from type T. Useful to focus on specific parts of a type.
Click to reveal answer
intermediate
How can you combine Omit<T, K> and Partial<Pick<T, K>> to make only some properties optional?
You can create a type that keeps all properties except K as they are, and makes only the properties K optional by combining Omit<T, K> with Partial<Pick<T, K>> using intersection (&).
Click to reveal answer
What does Readonly<Partial<T>> do to type T?
AMakes all properties optional and writable
BMakes all properties optional and read-only
CMakes all properties required and read-only
DMakes all properties required and writable
Which utility type would you use to select only some properties from a type?
APick
BOmit
CPartial
DRequired
How do you make only certain properties optional in a type T?
AUse <code>Omit&lt;T, K&gt; &amp; Partial&lt;Pick&lt;T, K&gt;&gt;</code>
BUse <code>Omit&lt;T, K&gt; &amp;&amp; Partial&lt;Pick&lt;T, K&gt;&gt;</code>
CUse <code>Partial&lt;T&gt;</code>
DUse <code>Required&lt;T&gt;</code>
What does Required<Partial<T>> result in?
AAll properties optional
BConflicting types, results in all properties optional
CConflicting types, results in all properties required
DAll properties required
Which utility type removes properties from a type?
APartial
BPick
COmit
DReadonly
Describe how you can combine utility types to create a type where some properties are optional and others are required.
Think about removing some properties and making only those optional.
You got /5 concepts.
    Explain the difference between combining Partial<Readonly<T>> and Readonly<Partial<T>>.
    Consider which properties become optional first and then read-only, or vice versa.
    You got /4 concepts.