Skip to content

Commit c30eb3d

Browse files
authored
Merge pull request #33 from deco-sites/jonasjesus/fix-deco-events-dispatch-type
fix(search): type-safe dispatch of search event (Form.tsx dispatch error)
2 parents d4c70a6 + c968c91 commit c30eb3d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/components/search/Searchbar/Form.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ export default function Searchbar(
5858
const onSubmit = () => {
5959
const term = inputRef.current?.value;
6060
if (term) {
61-
window.DECO?.events.dispatch({
61+
// `dispatch` exists at runtime (set up by the framework's DECO.events
62+
// bootstrap), but @decocms/apps' ambient Window.DECO type only declares
63+
// `subscribe`. Cast through the real shape to dispatch programmatically.
64+
const events = window.DECO?.events as unknown as
65+
| { dispatch?: (event: unknown) => void }
66+
| undefined;
67+
events?.dispatch?.({
6268
name: "search",
6369
params: { search_term: term },
6470
});

0 commit comments

Comments
 (0)