Getting started:
Related tutorials:
Getting started:
Related tutorials:
keyPressSources.pipe( | |
// Input handlers to take input value for searching | |
switchMap(value => { | |
return from(fetchCakesByName(value)).pipe( | |
// Only make an API request for searching after 0.5s since user stopped pressing a key | |
debounce(0.5), | |
// Retry 3 times if an API request fails | |
retry(3), | |
// Cancel the search when press Esc or clear input | |
takeUntil(value => value === 'Esc' || value === ''), |
import { Observable } from 'rxjs' | |
const observable = new Observable(observer => { | |
const array = [1,2,3,4,5] | |
array.forEach(number => { | |
if(!isOdd(number)) { | |
observer.error('Invalid even number') | |
} | |
observer.next(number) |
import {from} from 'rxjs/operators' | |
const fetchCakesPromise = fetch(getCakesEndpoint, {method: 'GET'}).then(res => res.data.cakes) | |
// Get cakes stream creation 🌈 | |
const cakeSource = from(fetchCakesPromise) | |
// Subscribe cake data and consume received cakes 🍽 | |
cakeSource.subscribe(console.log) |
functions: | |
todos: | |
handler: src/todos/todos.handler | |
events: | |
http: GET /todos |
const state = { | |
idle: "idle", | |
fetching: "fetching", | |
success: "success", | |
error: "error" | |
}; | |
const todoActions = { | |
fetchTodos: "fetchTodos", | |
cancelFetching: "cancelFetching", |
Resources: | |
MyInstance: | |
Type: AWS::EC2::Instance | |
Properties: | |
AvailabilityZone: "eu-north-1a" | |
ImageId: "ami-0c5254b956817b326" | |
InstanceType: "t3.micro" | |
KeyName: "ec2-general" | |
SecurityGroups: | |
- !Ref HTTPSecurityGroup |
When I first onboarded TypeScript world from JavaScript, one of the most confusing thing is the unknown
type. Remember when your coworkers write something like:
const foo = () => bar as unknown as any // <- 🤷🏻♂️🤷🏻♂️🤷🏻♂️
Let's take a look at TypeScript official documentation:
// Anything is assignable to unknown | |
const foo: unknown = 1 // <- we can assign a number to a unknown var | |
const bar: unknown = true // <- same with other primitive types such as boolean | |
// But unknown isn’t assignable to anything but itself | |
const myString: string = foo // <- ⛔️⛔️⛔️ unknown type is not assignable to string type | |
const isGreaterThan10 = (val: unknown) => val > 10 // <- ⛔️⛔️⛔️ because val has unknown type |
const getKeys = (obj: unknown) => { | |
return Object.keys(obj as object) // <- cast the type to be object | |
} | |
const getObject = (): object | undefined => { | |
// some code that return EITHER an object OR undefined 💣💣💣 | |
} | |
getKeys(getObject()) // <- 💣💥 when getObject() returns undefined |