It's perplexing to me why TypeScript doesn't allow the following:
type aToB = <A, B> (a:A) => B;
const id : aToB = x => x;
I keep getting the error: Type A is not assignable to type B.
What confuses me is that the type definition
type aToB = <A, B> (a:A) => B
does not imply that A must be different from B.
In mathematics, a function signature like f: A -> B
does not require A
to be distinct from B
. For example, a function such as f: Nat -> Nat
fits perfectly within f: A -> B
.
Is it just TypeScript behaving oddly in this sense, or am I overlooking something obvious?