Skip to content

Commit c2a551e

Browse files
committed
fix(react): replace triple as-cast chain with Set-based type guard in groupExportsByKind
1 parent 5db7924 commit c2a551e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/react/src/components/shared.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@ export interface CategoryGroup {
1717
exports: SpecExport[];
1818
}
1919

20+
const DISPLAY_KIND_SET: Set<string> = new Set(DISPLAY_KIND_ORDER);
21+
function isDisplayKind(kind: string): kind is DisplayKind {
22+
return DISPLAY_KIND_SET.has(kind);
23+
}
24+
2025
export function groupExportsByKind(exports: SpecExport[]): CategoryGroup[] {
2126
const groups = new Map<DisplayKind, SpecExport[]>();
2227

2328
for (const exp of exports) {
24-
const kind = exp.kind as string;
25-
if (!(DISPLAY_KIND_ORDER as string[]).includes(kind)) continue;
26-
const displayKind = kind as DisplayKind;
27-
const list = groups.get(displayKind) || [];
29+
if (!isDisplayKind(exp.kind)) continue;
30+
const list = groups.get(exp.kind) || [];
2831
list.push(exp);
29-
groups.set(displayKind, list);
32+
groups.set(exp.kind, list);
3033
}
3134

3235
return DISPLAY_KIND_ORDER.filter((kind) => groups.has(kind)).map((kind) => ({

0 commit comments

Comments
 (0)