SirHaus
SirHaus
TTCTheo's Typesafe Cult
Created by SirHaus on 5/10/2023 in #questions
Typescript function parameter into returnType
Here's my function:
export const useSomething = <Data extends object>(
func: (values?: Data) => Promise<any>,
name?: string
)
export const useSomething = <Data extends object>(
func: (values?: Data) => Promise<any>,
name?: string
)
It returns as below
return {} as returnType<Data,Name>
return {} as returnType<Data,Name>
I want to use the function in the below syntax:
useSomething<SomeInterface>(TestFunction, 'test')
useSomething<SomeInterface>(TestFunction, 'test')
and not
useSomething<SomeInterface,'test'>(TestFunction, 'test')
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?
3 replies