Utility Types — Concept Check
Questions on Utility Types. Partial, Pick, Omit, Record, ReturnType and friends. Deriving types from other types is what keeps them in sync when the source changes.
Questions in this quiz
8 questions on Utility Types — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer wants to create a type for a form that updates a user's name and email but not their ID. Which utility type should they use?
- APick<User, 'name' | 'email'>
- BOmit<User, 'id'>
- CPartial<Pick<User, 'name' | 'email'>>
- DPartial<Omit<User, 'id'>>
2.A team is using TypeScript and needs to ensure that all fields of a User object are immutable. Which utility type should they apply?
- ARequired<User>
- BPartial<User>
- CReadonly<User>
- DOmit<User, 'id'>
3.Given a function getConfig that returns an object, how can you derive the type of its return value?
- AUse Record<'getConfig', any>
- BUse Parameters<typeof getConfig>
- CUse ReturnType<typeof getConfig>
- DUse typeof getConfig
4.A developer mistakenly believes that using 'as const' on an array changes its type to 'string[]'. What is the actual effect?
- AIt has no effect on the array type.
- BIt converts the array to a union of its elements.
- CIt changes the array type to 'string[]'.
- DIt creates a readonly tuple type with literal values.
5.A developer needs a type that represents only the 'success' and 'error' statuses from a Status union. Which utility type should they use?
- AExclude<Status, 'idle'>
- BPick<Status, 'success' | 'error'>
- CExtract<Status, 'success' | 'error'>
- DOmit<Status, 'idle'>
6.A developer uses Record<'easy' | 'hard', number> to define a type. What does this type represent?
- AA type with optional 'easy' and 'hard' properties.
- BAn array of numbers indexed by 'easy' and 'hard'.
- CAn object with keys 'easy' and 'hard', both having number values.
- DA union of 'easy' and 'hard' with number values.
7.What happens when you rename a field in a type that is used with utility types like Partial, Pick, or Omit?
- AThe code breaks at runtime due to mismatched types.
- BDerived types become invalid and cause compile errors.
- COnly the original type updates, derived types must be manually updated.
- DAll derived types automatically update to reflect the change.
8.A developer wants to ensure that a function parameter accepts only the keys of a DEFAULTS object. How can they achieve this?
- AUse Record<keyof DEFAULTS, any>
- BUse keyof typeof DEFAULTS
- CUse Pick<typeof DEFAULTS, 'keys'>
- DUse typeof DEFAULTS