Is it possible to require a generic type on a function without parameters?
Example:
function myFunc<T>() {
return {} as T
}
const a = myFunc() // a: unknown
I want to make the generic type required, but couldn't find anything about it.
function myFunc<T>() {
return {} as T
}
const a = myFunc<SomeObject>() // a:SomeObject
seems to work just fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With