type Laptop = {
    variant: "laptop";
    cpu: string;
}

type Phone = {
    variant: "phone";
    camera: string;
}

type Product  = {
    price: number;
} & (Laptop | Phone)


// Correct
const product: Product = {
    variant: "laptop",
    cpu: "Intel",
    price: 1220
}

// Error
const product: Product = {
    variant: "phone",
    cpu: "Intel",
    price: 860
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: