Created
November 26, 2018 11:40
-
-
Save ragmha/23021a172d0cea7ff6adba7a4eef8214 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Sizes { | |
sizes: string[]; | |
} | |
interface Pizza extends Sizes { | |
name: string; | |
toppings?: number; | |
getAvailableSizes(): void; | |
[key: number]: string; // TypeScript index signatures must either be a ´string´ or a ´number´ | |
} | |
let pizza: Pizza; | |
function createPizza(name: string, sizes: string[]): Pizza { | |
return { | |
name, | |
sizes, | |
getAvailableSizes() { | |
return this.sizes; | |
}, | |
}; | |
} | |
pizza = createPizza("Pepperoni", ["small", "medium", "large"]); | |
pizza[1] = "PizzaHut"; | |
pizza.toppings = 2; | |
console.log(`And the Pizza is => ${JSON.stringify(pizza)}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment