Skip to content

Instantly share code, notes, and snippets.

@Adophilus
Created August 28, 2023 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adophilus/700d6c3e9c9b9530b1fa3207024181b4 to your computer and use it in GitHub Desktop.
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
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