Typescript function parameter into returnType

Here's my function:

export const useSomething = <Data extends object>(
    func: (values?: Data) => Promise<any>,
    name?: string
)

It returns as below
return {} as returnType<Data,Name>

I want to use the function in the below syntax:
useSomething<SomeInterface>(TestFunction, 'test')

and not
useSomething<SomeInterface,'test'>(TestFunction, 'test')

🤨 How can I create the type Name
  • from the value of the parameter
    name
    - and use it in the returnType thing so I avoid typing 'test' twice in the call?
Was this page helpful?