Skip to content

Commit

Permalink
Added an example of type literals
Browse files Browse the repository at this point in the history
  • Loading branch information
raahimfareed committed Oct 2, 2022
1 parent b29c429 commit 3047a43
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Typescript/type-literals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
type Size = "XL" | "LG" | "MD" | "SM" | "XS";
type Goods = "Pants" | "Shirt" | "Shoes" | "Hat" | "Gloves";

/**
* Product has combinations such as
* XL Pants
* LG Pants
* ...
* XS Pants
* XL Shirt
* ...
* SM Shirt
* XS Shirt
* ...
* XS Gloves
*/
type Product = `${Size} ${Goods}`;

let product: Product = "MD Gloves";

// MD Gloves
console.log(product);

// Error: Type '"Hello World"' is not assignable
// product = "Hello World";

0 comments on commit 3047a43

Please sign in to comment.