JSMonk / hegel

An advanced static type checker
https://hegel.js.org
MIT License
2.1k stars 59 forks source link

Two generic functions #284

Open polemius opened 4 years ago

polemius commented 4 years ago

First of all thank you for such a great project. I really like it 👍

I was playing around generic function and found that this code show the error:

function id<T>(x: T): T {
  return x
}

function composition<A, B, C>(
  f: (p1: A) => B,
  g: (p2: B) => C,
): (p: A) => C {
  return (x: A) => g(f(x))
}

const a = (x: number) => x + 1
const comp = composition(a, id) // this function is ok

// but this one has an error
// Type "<T>(T) => T" is incompatible with type "<T>(T) => number"
const comp2 = composition(id, a)

I don't know if it is even a bug.

JSMonk commented 4 years ago

Oh, thank you a lot @polemius. We will fix it. You are awesome ^_^