Index Access Types

Index Access
πŸ‘¨β€πŸ’Ό Index access types let you extract property types from other types using bracket notation.
type Recipe = {
	title: string
	author: { name: string; rating: 1 | 2 | 3 | 4 | 5 }
}

type TitleType = Recipe['title'] // string
type AuthorType = Recipe['author'] // { name: string; rating: 1 | 2 | 3 | 4 | 5 }
type RatingType = Recipe['author']['rating'] // 1 | 2 | 3 | 4 | 5
🐨 Open
index.ts
and:
  1. Extract nested property types
  2. Use unions to get multiple property types at once
  3. Combine with keyof for flexible access

Please set the playground first

Loading "Index Access Types"
Loading "Index Access Types"
Login to get access to the exclusive discord channel.
Loading Discord Posts