Recall & Review
beginner
What does the
Pick type do in TypeScript?The
Pick type creates a new type by selecting specific properties from an existing type. It helps to focus on only the needed parts of a type.Click to reveal answer
beginner
How do you use
Pick to select properties 'name' and 'age' from a type Person?You write: <br>
type PersonInfo = Pick<Person, 'name' | 'age'>;<br>This creates a new type with only name and age from Person.Click to reveal answer
intermediate
Why is
Pick useful in real projects?It helps to reuse existing types but only keep the parts you need. This makes code simpler and safer by avoiding extra properties.
Click to reveal answer
intermediate
What happens if you try to
Pick a property that does not exist in the original type?TypeScript will give an error because you can only pick keys that exist in the original type.
Click to reveal answer
advanced
Can
Pick be combined with other utility types?Yes! You can combine
Pick with types like Partial or Readonly to create flexible and precise types.Click to reveal answer
What does
Pick<T, K> do in TypeScript?✗ Incorrect
Pick selects specific properties K from type T to create a new type.Which syntax correctly picks properties 'id' and 'title' from type Book?
✗ Incorrect
The keys must be a union of string literals, like 'id' | 'title'.
What error occurs if you pick a property not in the original type?
✗ Incorrect
TypeScript checks keys at compile time and errors if keys don't exist.
Can
Pick be used to create a type with all properties optional?✗ Incorrect
Pick selects properties but does not change optionality; Partial makes properties optional.Which utility type can be combined with
Pick to make picked properties readonly?✗ Incorrect
Readonly makes properties readonly and can wrap a Pick type.Explain how the
Pick type works and give an example of its syntax.Think about choosing only some keys from a bigger object type.
You got /3 concepts.
Describe a situation where using
Pick would make your TypeScript code better.Imagine you only need a few details from a big object.
You got /3 concepts.