sindresorhus / camelcase-keys

Convert object keys to camel case
MIT License
679 stars 92 forks source link

Using function with inferred type does not resolve correct return type defaults #116

Closed WoodyWoodsta closed 11 months ago

WoodyWoodsta commented 11 months ago

If I have a function which has a return type involving an inferred generic type, the defaults on the call to the camelCaseKeys function return type incorrectly resolve to unknown:

export function handleResponse<T extends Record<string, unknown> | readonly unknown[]>(
  response: T,
): CamelCaseKeys<T, true> {
  return camelcaseKeys(response.data, { deep: true });
//^^^^^^ Type 'CamelCaseKeys<T, true, unknown, unknown, unknown, unknown, "">' is not assignable to type 'CamelCaseKeys<T, true>'
}

I expect the defaults to correctly resolve, as they do in the return type of my handleResponse function: CamelCaseKeys<T, true>.

sindresorhus commented 11 months ago

// @yutak23