mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
[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>
This commit is contained in:
parent
97cb7331e7
commit
ab710a881e
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user