Skip to content

Commit cf64ea1

Browse files
committed
test(components): draw the param dialog host without casts
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUba5gmu4hkimKCSC6
1 parent b6b7bdb commit cf64ea1

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

‎ui/packages/components/src/__tests__/element-button-paramDialogDescription-29249.test.tsx‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,17 @@ const DESCRIPTION = {
6363
*/
6464
function ParamHost({ action }: { action: Record<string, unknown> }) {
6565
const { t } = useObjectTranslation();
66-
const [dialog, setDialog] = React.useState<{ title?: unknown; description?: unknown } | null>(null);
66+
const [dialog, setDialog] = React.useState<{ title: string; description: string } | null>(null);
6767
const onParamCollection = React.useCallback<ParamCollectionHandler>((_params, dispatched) => {
6868
handed.push(dispatched);
69-
setDialog({ title: dispatched?.label, description: dispatched?.description });
69+
// A non-string reaching the host is drawn as nothing, so the assertions
70+
// below see the gap instead of React refusing an object child.
71+
const title = dispatched?.label;
72+
const description = dispatched?.description;
73+
setDialog({
74+
title: typeof title === 'string' ? title : '',
75+
description: typeof description === 'string' ? description : '',
76+
});
7077
return new Promise(() => {});
7178
}, []);
7279
const C = ComponentRegistry.get('element:button');
@@ -77,15 +84,13 @@ function ParamHost({ action }: { action: Record<string, unknown> }) {
7784
schema={{
7885
type: 'element:button',
7986
properties: { label: { en: 'Invite member', 'zh-CN': '邀请成员' }, action },
80-
} as never}
87+
}}
8188
/>
8289
{dialog && (
8390
<Dialog open>
8491
<DialogContent>
85-
<DialogTitle>{dialog.title as string}</DialogTitle>
86-
<DialogDescription>
87-
{(dialog.description as string) || t('actionDialog.description')}
88-
</DialogDescription>
92+
<DialogTitle>{dialog.title}</DialogTitle>
93+
<DialogDescription>{dialog.description || t('actionDialog.description')}</DialogDescription>
8994
</DialogContent>
9095
</Dialog>
9196
)}

0 commit comments

Comments
 (0)