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 Tree { | |
branches: number | |
species: string | |
} | |
interface Vehicle { | |
position: number | |
speed: number | |
} | |
interface Animal { | |
legs: number |
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 Input <T> = string | number | T | |
const input1: Input<boolean> = true | |
const input2: Input<string[]> = true | |
type Collection <T> = [T, T, T] | |
const stringCollection: Collection<string> = ['a', 'b', 'c'] | |
const numberCollection: Collection<number> = ['a', 2, 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 Input = string[] | number[] | |
interface Tree { | |
branches: number | |
species: string | |
height: number | |
rings: number | |
} | |
interface WildTree extends Tree { |
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 Input <T> = string | number | T | |
const i: Input<boolean> = false | |
const x: Input<number[]> = [1, 2, 3] | |
interface Guest { | |
name: string | |
email: string | |
age: number |
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 Person { | |
name: string | |
age: number | |
email: string | |
phone: string | |
} | |
interface SpecialPerson extends Person { | |
reason: string | |
} | |
const tallulah: SpecialPerson = { |
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 Guest { | |
name: string | |
age: number | |
email: string | |
phone: string | |
address: string | |
} | |
type GuestKey = keyof Guest // 'name' | 'age' | 'email' | 'phone' | 'address' | |
const dorothy = { |
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
<script> | |
const review = { message: 'Those were some cute dogs!' } | |
const reviewJson = JSON.stringify(review) | |
localStorage.setItem('review', reviewJson) | |
const localReview = localStorage.getItem('review') | |
console.log('localReview', localReview) | |
console.log('localReview.message', localReview.message) | |
const parsedReview = JSON.parse(localReview) | |
console.log('parsedReview.message', parsedReview.message) | |
</script> |
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
<script> | |
async function upload () { | |
const review = { message: 'Those are some cute dogs!' } | |
const reviewJson = JSON.stringify(review) | |
const init = { | |
method: "POST", | |
body: reviewJson | |
} | |
const response = await fetch('https://dog.ceo/api/breeds/image/random', init) | |
const data = response.json() |
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
<img id="image" widt="400"/> | |
<script> | |
async function download () { | |
const response = await fetch('https://dog.ceo/api/breeds/image/random') | |
const data = await response.json() | |
console.log('data', data) | |
const image = document.getElementById('image') | |
image.src = data.message | |
} | |
download() |
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
<script> | |
// synchronous (wait) | |
console.log('before') | |
function sleep(ms) { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
resolve() | |
}, ms) | |
}) |
NewerOlder