[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:
Edaz 2021-11-10 12:08:47 +13:00 committed by GitHub
parent 97cb7331e7
commit ab710a881e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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