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.
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.
a will be typed as string but will contain a plain object.const a without you explicitly passing the type you want. check this stackoverflow.com/a/57548987/281474T but that's obviously not the same as requiring a type..