I would like to create a function that restricts the arguments passed. dpr and w should not be both passed at the same time. Here's my attempt:
interface W { w: number }
interface Dpr { dpr: number }
type Srcset<T> = { url: string } & WidthOrDpr<T>
type WidthOrDpr<T> = T extends W ? W : Dpr;
function formatSrcset<T extends W | Dpr>(options: Srcset<T>) {
}
formatSrcset({ url: '//', dpr: 1 }); // ok
formatSrcset({ url: '//', w: 1 }); // ok
formatSrcset({ url: '//', w: 1, dpr: 1 }); // should fail
I would like to avoid function overloads.