I am currently working on creating a versatile function that can take another function and deduce the return type automatically (similar to how map functions). Here is the code I have so far:
type game_selector<T> = <T>( state : GT.game_state ) => T
export function useGameState<T>( gs : game_selector<T> ): T {
When calling this function, it looks like this:
const users = useGameState( gs => gs.users )
Based on the error message received, it seems that the type of gs
is correctly inferred since it recognizes gs.users
as Users
, however, the following error occurs:
TS2322: Type 'Users' is not assignable to type 'T'
What would be the correct way to specify the typing for this function?