Our repo is making the type checker in VS code chug hard. Usually 10s before showing type errors or any Intellisense. Often it simply breaks & we have to restart the TS server. It is a larger code base with ~800 react components.
I’ve noticed it usually becomes much slower as soon as I import & call our useAPIQuery hook within a component. This is basically a wrapper around react-query.
I can use it like
const productsQuery = useAPIQuery('products', { searchParams/pathParams: (typed to products GET) })
The call signature is a union of about 160 types from different GET endpoints
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck The call queries[queryStr](params[0]) takes much longer to type-check as the number of queries grows
import queries, { APIQueryStr } from './queries'
const useAPIQuery = <T extends APIQueryStr>(
queryStr: T,
...params: Parameters<(typeof queries)[T]>
): ReturnType<Pick<typeof queries, T>[T]> => queries[queryStr](params[0])
export default useAPIQuery
I love how easy to use this is! The response/request/param types are magically given just providing a single queryStr like ‘products’, ‘organizations’, etc. However there is a huge performance impact with this approach.
Is there any way I can keep this interface externally in our application code but rework the types in a more efficient manner?