Attempting to reduce boilerplate, I'm declaring some sort of generic function interface as a type. Then I want to declare a const
of such type. So, why typescript assumes that foo
declaration is legit and bar
is not? Aren't these declarations practically identical? Is typescript lacking simple feature or am I missing some details? Is there any workarounds, if I do not want explicitly repeat FunctionType
interface?
type FunctionType<TValue> = (value: TValue) => void;
const foo = <TValue>(value: TValue): void => {
}
//const bar: FunctionType<TValue> = (value) => { // Cannot find name 'TValue'
//}