The type definition of a library (in this case react-query) looks like this:
export function useQuery<TResult, TKey extends AnyQueryKey, TError = Error>({
queryKey,
queryFn,
config,
}: {
queryKey: TKey
queryFn?: QueryFunction<TResult, TKey>
config?: QueryOptions<TResult, TError>
}): QueryResult<TResult, TError>
As we can see, the function is using 3 generic types (TResult, TKey and TError).
TResult and TKey are inferred automatically and that's awesome because we never have to type them manually.
However, I'm using a custom error class in my app and that's why I need to specify TError.
Of course, I'd like to do that without breaking the automatic inferring since that would result in unnecessary and annoying boilerplate in my code.
So my question is:
Can we skip specifying types like we can do with optional function parameters?