Skip to content

Commit

Permalink
Add support for ReadonlyArray<T> for keyResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
hugodelahousse committed May 31, 2024
1 parent 6480497 commit ad74796
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/batshit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ export const create = <T, Q, R = T>(
* @returns (item:T extends Array<A>, query: Q) => A
*/
export const keyResolver =
<T extends Array<any>, Q, R = T extends Array<infer A> ? A : never>(
key: T extends Array<infer A> ? keyof A : never
<T extends ReadonlyArray<any>, Q, R = T extends ReadonlyArray<infer A> ? A : never>(
key: T extends ReadonlyArray<infer A> ? keyof A : never
) =>
(items: T, query: Q): R =>
items.find((item) => item[key] == query) ?? null;
Expand Down

0 comments on commit ad74796

Please sign in to comment.