This file contains 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
menu = ['bun bo hue', 'cha ca', 'pho viet', 'banh xeo'] | |
price = { | |
"bun bo hue": 30, | |
"cha ca": 25, | |
"pho viet": 40, | |
"banh xeo": 10 | |
} | |
order = input('please make an order:') |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Page Title</title> | |
</head> | |
<body> | |
<div class="grandparent"> |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Page Title</title> | |
</head> | |
<body> | |
<div class="grandparent"> |
This file contains 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
// Unions | |
type NetworkLoadingState = { | |
state: "loading"; // Discriminant | |
}; | |
type NetworkFailedState = { | |
state: "failed"; // Discriminant | |
code: number; | |
}; |
This file contains 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 Options { | |
material: string; | |
backlight: boolean; | |
} | |
// Mapped types | |
type ReadOnly<T> = { readonly [k in keyof T]: T[k]; } | |
type Optional<T> = {[k in keyof T]?: T[k]; } | |
type Nullable<T> = {[k in keyof T]: T[k] | null; } | |
// Creating new types from mapped types |
This file contains 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 Cephalopod { | |
hasInk: boolean; | |
arms: number; | |
tentacles: number; | |
} | |
interface CephalopodDictionary { | |
[index: string]: Cephalopod; | |
} | |
let dictionary: CephalopodDictionary = {}; | |
dictionary['octopus vulgaris'] = { hasInk: true, arms: 8, tentacles: 0 }; |
This file contains 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
// Using bracket [] | |
let list: number[] = [1, 2, 3]; | |
// Using Array<elemType> | |
let list: Array<number> = [1, 2, 3]; |
This file contains 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 ErrorHandling { | |
success: boolean; | |
error?: { message: string }; | |
} | |
interface ArtworksData { | |
artworks: { title: string }[]; | |
} | |
interface ArtistsData { |
This file contains 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
// String Literal Types | |
type Easing = "ease-in" | "ease-out" | "ease-in-out"; | |
class UIElement { | |
animate(dx: number, dy: number, easing: Easing) { | |
if (easing === "ease-in") { | |
// ... | |
} else if (easing === "ease-out") { | |
} else if (easing === "ease-in-out") { |
This file contains 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
// variable | |
let union: boolean | number; | |
union = 5; // OK: number | |
union = true; // OK: boolean | |
union = 'string'; // Error: Type "string" is not assignable to type 'number | boolean' | |
// function | |
function padLeft(value: string, padding: string | number) { | |
// ... | |
} |
NewerOlder