Skip to content

Instantly share code, notes, and snippets.

@ragmha
Created November 26, 2018 11:25
Show Gist options
  • Save ragmha/4f8c3216061964d6f6492f0cf82f5456 to your computer and use it in GitHub Desktop.
Save ragmha/4f8c3216061964d6f6492f0cf82f5456 to your computer and use it in GitHub Desktop.
interface Sizes {
sizes: string[];
}
interface Pizza extends Sizes {
name: string;
toppings?: number;
getAvailableSizes(): void;
}
let pizza: Pizza;
function createPizza(name: string, sizes: string[]): Pizza {
return {
name,
sizes,
getAvailableSizes() {
return this.sizes;
},
};
}
pizza = createPizza("Pepperoni", ["small", "medium", "large", "xtra-large"]);
pizza.toppings = 2;
console.log(`Pizza created => ${JSON.stringify(pizza)}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment