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; | |
} |
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 Pizza { | |
name: string; | |
sizes: string[]; | |
getAvailableSizes(): void; | |
} | |
let pizza: Pizza; | |
function createPizza(name: string, sizes: string[]): Pizza { | |
return { |
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 Pizza { | |
name: string; | |
sizes: string[]; | |
} | |
let pizza: Pizza; | |
function createPizza(name: string, sizes: string[]): Pizza { | |
return { name, sizes }; | |
} |
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
const enum Sizes { | |
Small = "small", | |
Medium = "medium", | |
Large = "large", | |
} | |
let selected: Sizes = Sizes.Small; | |
function updateSize(size: Sizes): void { | |
selected = size; |
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
enum Sizes { | |
Small, | |
Medium, | |
Large, | |
} | |
enum Sizes { | |
ExtraLarge = 3, | |
} |
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
type Pizza = { name: string; toppings: number }; | |
const pizza: Pizza = { name: 'Blazing Inferno', toppings: 5 }; | |
const serialized = JSON.stringify(pizza); | |
function getNameFromJSON(obj: string) { | |
// return (<Pizza>JSON.parse(obj)).name; | |
return (JSON.parse(obj) as Pizza).name; | |
} |
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
type Size = "small" | "medium" | "large"; | |
type Callback = (size: Size) => void; | |
let pizzaSize: Size = "small"; | |
const selectSize: Callback = x => (pizzaSize = x); | |
selectSize("medium"); | |
console.log(`Pizza size: ${pizzaSize}`); |
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
let pizza: [string, number, boolean]; | |
pizza = ["Pepperoni", 20, true]; |
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
let sizes: number[]; | |
sizes = [1, 2, 3]; | |
let toppings: Array<string>; | |
toppings = ["pepperoni", "tomato", "baby"]; |
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
let pizza: { name: string; price: number; getName(): string } = { | |
name: "Plain Old Pepperoni", | |
price: 20, | |
getName() { | |
return pizza.name; | |
}, | |
}; | |
console.log(pizza.getName()); |