Here is my first attempt: (playground link)
/** Trigger a compiler error when a value is _not_ an exact type. */
declare const exactType:
Here's the most robust solution I've found thus far:
// prettier-ignore
type Exact = (() => T extends A ? 1 : 0) extends (() => T extends B ? 1 : 0)
? (A extends B ? (B extends A ? unknown : never) : never)
: never
/** Fails when `actual` and `expected` have different types. */
declare const exactType: (
actual: Actual & Exact,
expected: Expected & Exact
) => Expected
Thanks to @jcalz for pointing in the right direction!