Partial and Pick

Partial Pick
πŸ‘¨β€πŸ’Ό We need to create types for updating user data. Some fields should be optional, and we only want to allow updating specific fields.
type Article = {
	id: string
	title: string
	body: string
	updatedAt: Date
}

type ArticlePatch = Partial<Pick<Article, 'title' | 'body'>>
🐨 Open
index.ts
and:
  1. Create PartialUser β€” all User properties optional
  2. Create UserNameEmail β€” only name and email
  3. Create UserUpdate β€” optional updates limited to name and/or email
  4. Remove the @ts-expect-error once UserUpdate exists
  5. Export updateUser
Observable behavior for the provided user fixture:
  • updateUser(user, { name: 'Alice Smith' }) β†’ name becomes 'Alice Smith', email stays 'alice@example.com', id stays '1'
  • updateUser(user, { email: 'alice.smith@example.com' }) β†’ email updates, name stays 'Alice'
  • Updating both fields at once also works
  • Updating id should be a type error

Please set the playground first

Loading "Partial and Pick"
Loading "Partial and Pick"