If I declare the following types:
export type Type1 = { id: string } | { id: number };
export type Type2 = { id: string } | { id: number };
Why do I get an error when used in the following manner:
function displayItem(item: Type1) {
loadItem({ id: item.id }); // error is indicated here
}
function loadItem(item: Type2) {}
My understanding from https://www.typescriptlang.org/docs/handbook/type-compatibility.html is that they should be equivalent as they are structurally the same.
Simpler repro in light of answers (second type is not needed):
export type Type1 = { id: string } | { id: number };
function displayItem(item: Type1) {
loadItem({ id: item.id }); // error is indicated here
}
function loadItem(item: Type1) {}
