I like to write my TypeScript functions in a functional style. When it comes to simple functions, I usually do something like this:
type A = (value: number) => string;
const a: A = value => value.toString();
But when it comes to using generic types, things can get a bit more complicated. How can I maintain that simplicity with a function like this?
function a<T>(value: T): T {
return value;
}
Just adding a generic type doesn't work as expected:
type A = <T>(value: T) => T;
const a: A = value => value; // `value` implicitly has an `any` type
Is there a better way to achieve this?