Last Updated: May 22, 2026
Method-based constraints can only describe what a type does, not what it is. That's a problem the moment you want a generic function that adds numbers, compares with <, or uses any other operator. Type sets fix this by letting a constraint list concrete types directly, with two extra tools: the union operator | for "any of these" and the approximation prefix ~ for "any type whose underlying type is this." This chapter covers how type sets are spelled, what operators they unlock, how to mix them with method requirements, and how to package the common ones as reusable named constraints.