Created
August 28, 2023 07:41
-
-
Save Adophilus/700d6c3e9c9b9530b1fa3207024181b4 to your computer and use it in GitHub Desktop.
some code to analyse the difference between the union (|) and intersection (&) operates in typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Product = { | |
price: number | |
sku: string | |
brands: { | |
_ref: string | |
} | |
categories: { | |
_ref: string | |
} | |
} | |
type ProductBrand = { | |
name: string | |
logo: string | |
} | |
type ProductCategory = { | |
name: string | |
} | |
type ProductWithBrands = Omit<Product, "brands"> & { | |
brands: ProductBrand | |
} | |
type ProductWithCategories = Omit<Product, "categories"> & { | |
categories: ProductCategory | |
} | |
let product: Product | |
let productWithBrands: ProductWithBrands | |
let productWithCategories: ProductWithCategories | |
let productWithBrandsAndCategories: ProductWithBrands & ProductWithCategories |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment