Skip to content

Commit 79745d1

Browse files
Fix: Program Viewer crash when using unnamed union variants (microsoft#2941)
1 parent 2d6e138 commit 79745d1

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
3+
changeKind: fix
4+
packages:
5+
- "@typespec/html-program-viewer"
6+
---
7+
8+
Fix: Program Viewer crash when using unnamed union variants

packages/html-program-viewer/src/ui.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const TypeSpecProgramViewer: FunctionComponent<TypeSpecProgramViewerProps
6969
};
7070

7171
export interface ItemListProps<T> {
72-
items: Map<string, T> | T[];
72+
items: Map<string | symbol, T> | T[];
7373
render: (t: T) => ReactElement<any, any> | null;
7474
}
7575

@@ -85,8 +85,8 @@ export const ItemList = <T extends object>(props: ItemListProps<T>) => {
8585
}
8686
return (
8787
<KeyValueSection>
88-
{[...props.items.entries()].map(([k, v]) => (
89-
<li key={k}>{props.render(v)}</li>
88+
{[...props.items.entries()].map(([k, v], i) => (
89+
<li key={typeof k === "symbol" ? i : k}>{props.render(v)}</li>
9090
))}
9191
</KeyValueSection>
9292
);

packages/html-program-viewer/test/smoke-test.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ describe("html-program-viewer: smoke tests", () => {
1212
it("create html view", async () => {
1313
await runner.compile(`op foo(): string;`);
1414
});
15+
16+
it("compile unnamed union variant without error", async () => {
17+
await runner.compile(`union Foo { "a", "b" }`);
18+
});
1519
});

0 commit comments

Comments
 (0)