If TypeScript is.... adding types... what is this, and why is this allowed?

export type InternalAddress = {
firstName: string;
lastName: string;
kind: "internal";
}
export type InternalAddress = {
firstName: string;
lastName: string;
kind: "internal";
}
it's in relation to
export type Address = InternalAddress | ExternalAddress;

export function formatAddresses(addresses: Address[]) {
let formatted = "";
for (const address of addresses) {
if (address.kind === "internal") {
formatted += `${address.firstName}.${address.lastName}@support.ai, `;
}
if (address.kind === "external") {
formatted += `${address.username}@${address.domain}, `;
}
}
return formatted.slice(0, -2);
}
export type Address = InternalAddress | ExternalAddress;

export function formatAddresses(addresses: Address[]) {
let formatted = "";
for (const address of addresses) {
if (address.kind === "internal") {
formatted += `${address.firstName}.${address.lastName}@support.ai, `;
}
if (address.kind === "external") {
formatted += `${address.username}@${address.domain}, `;
}
}
return formatted.slice(0, -2);
}
1 Reply
CDL
CDLOP4w ago
is it just a step further than :string; ? so it's saying hey I want kind to be of type string BUT it has to be also of value "internal" ?

Did you find this page helpful?