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 from ApiResponse (data, user, profile, and a single post)
  2. Extract a type that covers both the status and error property types
  3. Create a type for all possible value types of the nested user type
  4. Create and export these fixtures typed with your extracted types:
    • profile: { avatar: 'https://example.com/avatar.jpg', bio: 'Hello!' }
    • post: { id: '1', title: 'Hello World', published: true }
    • user: { id: '1', name: 'Alice', profile: { avatar: 'url', bio: 'bio' } }
Completion check: those three exports match the fixtures above.

Please set the playground first

Loading "Index Access Types"
Loading "Index Access Types"