type Identity = <T>(input: T) => T
const identity: Identity = (input: number) => input;
When using generics like this, it results in a compiler error:
Type '(input: number) => number' is not compatible with type 'Identity'.
Parameters 'input' and 'a' have incompatible types.
Type 'T' cannot be assigned to type 'number'.
To resolve this, we can define the generic type as follows:
type Identity<T> = (input: T) => T
But sometimes, we may not want to explicitly declare the type every time. Is there a way for it to be inferred or flow through automatically?