Skip to content

Commit faa2256

Browse files
pawelgrimmclaude
andcommitted
refactor: drop non-null assertions in avatar collection stories
Tighten getContributor / getWorkspaceName return types and extract the workspace helper so callers don't need ! everywhere. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ead5e38 commit faa2256

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

src/avatar/avatar-pair.stories.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ const contributors = [
1515

1616
const workspaceNames = ['Reactist', 'Todoist', 'Twist', 'Doist'] as const
1717

18-
function getContributor(index: number) {
19-
return contributors[index % contributors.length]
18+
function getContributor(index: number): (typeof contributors)[number] {
19+
return contributors[index % contributors.length]!
20+
}
21+
22+
function getWorkspaceName(index: number): (typeof workspaceNames)[number] {
23+
return workspaceNames[index % workspaceNames.length]!
2024
}
2125

2226
function getGithubAvatarUrl(githubUserId: string, width: number) {
@@ -194,8 +198,8 @@ export const Sizes = {
194198
{([80, 62, 50, 36, 28, 20, 16, 12] as const).map((size, index) => (
195199
<AvatarExample key={size} label={`${size}px`}>
196200
<AvatarPair size={size}>
197-
<UserAvatar contributor={getContributor(index)!} size={size} />
198-
<UserAvatar contributor={getContributor(index + 1)!} size={size} />
201+
<UserAvatar contributor={getContributor(index)} size={size} />
202+
<UserAvatar contributor={getContributor(index + 1)} size={size} />
199203
</AvatarPair>
200204
</AvatarExample>
201205
))}
@@ -210,14 +214,8 @@ export const Sizes = {
210214
{([80, 62, 50, 36, 28, 20, 16, 12] as const).map((size, index) => (
211215
<AvatarExample key={size} label={`${size}px`}>
212216
<AvatarPair size={size} shape="rounded">
213-
<WorkspaceAvatar
214-
size={size}
215-
name={workspaceNames[index % workspaceNames.length]!}
216-
/>
217-
<WorkspaceAvatar
218-
size={size}
219-
name={workspaceNames[(index + 1) % workspaceNames.length]!}
220-
/>
217+
<WorkspaceAvatar size={size} name={getWorkspaceName(index)} />
218+
<WorkspaceAvatar size={size} name={getWorkspaceName(index + 1)} />
221219
</AvatarPair>
222220
</AvatarExample>
223221
))}

0 commit comments

Comments
 (0)