Why is my SupposedId type below not a type identity?
Typescript is complaining that Type 'T' is not assignable to type 'SupposedId<T>'.
How comes T cannot be assignable to either T or T, what am I missing?
type SupposedId<T> = T extends object ? T : T;
function makeId<T>(test: T): SupposedId<T> {
return test // <- Type 'T' is not assignable to type 'SupposedId<T>'
}
SupposedId? I'm not asking to dismiss the issue (which is definitely interesting), but it may help us understand your end goal.SupposedId<T>is not correctly defining a type identity. It is saying that ifTextends object, thenSupposedId<T>is equal toT, otherwise it's equal toT. Since all types extend object,Twill always be assignable toT, but not toSupposedId<T>. You should change your definition to:type SupposedId<T> = T;This way,SupposedId<T>will be the exact same type asTand the function makeId will work as expected.object- primitives such as string, number, and bool are not objects.