I wanted to know why I had to append & IRedirectRow to my extends clause in order for Pick to actually, er, pick up the keys in the following:
interface IRedirectRow extends QueryResultRow {
lookup_key: string;
url: string;
}
type RedirectRow<T = unknown> = (T extends keyof IRedirectRow
? Pick<IRedirectRow, T>
: IRedirectRow) &
IRedirectRow;
const result = getRedirectRow();
// url is a valid property with the "& IRedirectRow" appendage
// url is NOT valid once you remove the appendage, why?
console.log(result.url);
The moment I remove the appendage, the inferred return type changes from Pick<"lookup_key" | "url"> to Pick<"lookup_key"> | Pick<"url"> and I don't understand why that happens. Reading the extends clause docs now but it's not clicking.