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. Use Partial<User> to create a type where all properties are optional
  2. Use Pick<User, 'name' | 'email'> to create a type with only name and email
  3. Combine them to create UserUpdate that only allows updating name and email

Please set the playground first

Loading "Partial and Pick"
Loading "Partial and Pick"
Login to get access to the exclusive discord channel.
Loading Discord Posts