feat: allow extra arguments in Insights API#1210
Conversation
| typeof createSearchInsightsApi | ||
| >; | ||
|
|
||
| export type WithArbitraryParams<TParams extends Record<string, unknown>> = |
There was a problem hiding this comment.
It's technically an all-purpose utility type, but since it's only being used here for now, it seemed like an unnecessary hassle to move it to shared.
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 0b43fc9:
|
| sendToInsights( | ||
| 'clickedObjectIDsAfterSearch', | ||
| mapToInsightsParamsApi(params), | ||
| mapToInsightsParamsApi< |
There was a problem hiding this comment.
The way mapToInsightsParamsApi is typed is what's causing the typing issues I was encountering. When I inline the implementation of mapToInsightsParamsApi directly, the issue disappears.
I'm not sure what's going on exactly in how TypeScript interprets it all, but when unioning a strict record with an arbitrary record, the generic type TInsightsParamsType loses all the mandatory properties and the return type only contains objectIDs.
I'm doubtful we can fix this at the mapToInsightsParamsApi level, so the pragmatic option seems to cast.
Lmk if you have a working option that works better.
Summary
This types and tests the exposed Insights API to allow passing extra arguments in the payload.
This was already possible, but would have resulted in typing violations for TypeScript users.
FX-2652