Hi, I am a bit confused with how conditional types play with return types of functions. e.g. I would have expected the following bit of code to work but it fails with Type '{ key: T; }' is not assignable to type 'Ret<T>' playground link
type Ret<T> = T extends string ? { key: string } : { key: number };
function fun<T extends string>(x: T): Ret<T> {
return {
key: x,
};
}
My thinking is that since T is assignable to a string, Ret<T> should expand to be { key: string }. Even if I change Ret<T> to return a { key: T } it still fails. Thanks in advance!