Skip to content

Instantly share code, notes, and snippets.

@kenmori
Last active August 11, 2019 01:28
Show Gist options
  • Save kenmori/542f1741831d4ed3d0518b78d88e062c to your computer and use it in GitHub Desktop.
Save kenmori/542f1741831d4ed3d0518b78d88e062c to your computer and use it in GitHub Desktop.
F-bounded polymorphism
// ここではそれぞれの型引数(T,U)はお互いの関係性は知らない
function someFunction <T, U> (t: T, u: U): T {
  return t;
}

const dog = someFunction(new Dog(), new Cat());

// これを `T extends U` とすることで第二引数のU型を制約とするTになった
function someFunction <T extends U, U> (t: T, u: U): T {
  return t;
}

これをF-bounded polymorphismという

https://stackoverflow.com/questions/39176786/what-is-f-bounded-polymorphism-in-typescript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment