diff options
author | Marcel Ribeiro Dantas <ribeirodantasdm@gmail.com> | 2022-06-27 00:28:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-27 00:28:16 +0200 |
commit | 5d133e847846b4c8d436f7a567674c2e1df35a13 (patch) | |
tree | 7ebc7704f02ceef195a8896a80a06ed81cc12585 /typescript.html.markdown | |
parent | 27f7f03401ff747a61a912fdf73549b1788b13e1 (diff) | |
parent | 8f28c8021b8ce3cb791861ad19c41e12228d8bcd (diff) |
Merge branch 'master' into patch-1
Diffstat (limited to 'typescript.html.markdown')
-rw-r--r-- | typescript.html.markdown | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/typescript.html.markdown b/typescript.html.markdown index f7a41ce1..74cd15c6 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -48,6 +48,7 @@ let list: Array<number> = [1, 2, 3]; // For enumerations: enum Color { Red, Green, Blue }; let c: Color = Color.Green; +console.log(Color[c]); // "Green" // Lastly, "void" is used in the special case of a function returning nothing function bigHorribleAlert(): void { @@ -237,6 +238,16 @@ if (state.type === "success") { console.error(state.message); } +// Template Literal Types +// Use to create complex string types +type OrderSize = "regular" | "large"; +type OrderItem = "Espresso" | "Cappuccino"; +type Order = `A ${OrderSize} ${OrderItem}`; + +let order1: Order = "A regular Cappuccino"; +let order2: Order = "A large Espresso"; +let order3: Order = "A small Espresso"; // Error + // Iterators and Generators // for..of statement |