diff options
author | Edaz <edazpotato@gmail.com> | 2021-11-10 12:08:47 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-10 00:08:47 +0100 |
commit | ab710a881edf161eb96036f8b0b523057f39a290 (patch) | |
tree | 48c37c4e0ef97907c20f77b8093ccdc7a4fe849a | |
parent | 97cb7331e768cd8cce41e6b164fb4b0ff7915939 (diff) |
[typescript/en] Add template literal types (#4265)
* Add template literal types
* Update typescript.html.markdown
Co-authored-by: Andre Polykanine <ap@oire.me>
Co-authored-by: Andre Polykanine <ap@oire.me>
-rw-r--r-- | typescript.html.markdown | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/typescript.html.markdown b/typescript.html.markdown index 64be9401..74cd15c6 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -238,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 |