Improve type safety on API call parameters in the frontend
In case we change a request parameter name on the backend, we currently don't get an error by TypeScript. The same is true if we add a new non-optional request parameter on the backend.
For example, the following code in UserManage.tsx
:
useEffect(() => {
dispatch({ type: LOAD_USERS.request, includeInactive: true });
}, [dispatch]);
Currently, if you change includeInactive
to includeActive
or includInactive
or add any parameter that doesn't exist on the API, it will still compile without any errors (even though it's not present on the type of the request in the generated backend API). This is also true if we change the includeInactive
parameter to a different name on the backend.
This means that currently when we perform changes to request parameters, we need to be careful to remember to also change all of the occurrences on the frontend as well. This is not ideal, as this could result in bugs that are difficult to debug and it could also easily slip in a code review.
Since we already have the typing information (like in BackendApi.ts
ListUsersRequest
in the example above), we should use it to improve the typing in such cases, so that TypeScript throws an error if a request parameter is attempted to be used that isn't available on the backend.