Effect CommunityEC
Effect Communityβ€’3y agoβ€’
102 replies
steida

Understanding TypeScript's useQueries Function

Sometimes, I think I don't understand TypeScript at all. I need useQueries function that takes a tuple of queries and maps it to a tuple of QueryResults. This code works but any is lame. It would be Row, but then it doesn't work. Any idea, please?

readonly useQueries: <T extends ReadonlyArray<Query<any>>>(
    queries: T,
  ) => { [P in keyof T]: T[P] extends Query<infer U> ? QueryResult<U> : never };


This is not working:

readonly useQueries: <R extends Row, T extends ReadonlyArray<Query<R>>>(
    queries: T,
  ) => { [P in keyof T]: T[P] extends Query<infer U> ? QueryResult<U> : never };
Was this page helpful?