Type parameters as constraints

With TypeScript 1.8 it becomes possible for a type parameter constraint to reference type parameters from the same type parameter list. Previously this was an error. This capability is usually referred to as F-Bounded Polymorphism.

Example
  1. function assign<T extends U, U>(target: T, source: U): T {
  2. for (let id in source) {
  3. target[id] = source[id];
  4. }
  5. return target;
  6. }
  7. let x = { a: 1, b: 2, c: 3, d: 4 };
  8. assign(x, { b: 10, d: 20 });
  9. assign(x, { e: 0 }); // Error