Reputation: 31
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.
Upvotes: 3
Views: 2472
Reputation: 1489
function myFunc<T>() {
return {} as T
}
const a = myFunc<SomeObject>() // a:SomeObject
seems to work just fine.
Upvotes: 3