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
class Foo { | |
options = { | |
ns: this.namespaces | |
}; | |
constructor(namespaces = []) { | |
this.namespaces = namespaces; | |
} | |
} |
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 Milestone { | |
label: string; | |
count: number; | |
} | |
interface Options { | |
separator?: string; | |
} | |
const format = (milestones: Milestone[], options: Options = { separator: ' ' }): string => |
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
/** | |
* A.K.A. type guard | |
*/ | |
type Refinement<T, U extends T> = (candidate: T) => candidate is U; | |
function isString(candidate: unknown): candidate is string { | |
return typeof candidate === 'string'; | |
} |
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 retry = (maxAttemps: number) => <T>(thunk: () => Promise<T>): () => Promise<T> => { | |
let attempts = 0; | |
const attempt = async (): Promise<T> => { | |
attempts++; | |
let result: T; | |
try { | |
result = await thunk(); | |
} catch(error) { |
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 Dog { | |
name: string; | |
bark(): void; | |
} | |
declare global { | |
namespace Pick { | |
type ByValue<T, U> = Pick<T, PropertyOfValue<T, U>> | |
} | |
} |
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
class Node { | |
next: Node | null = null; | |
constructor(readonly data: number) {} | |
} | |
class LinkedList { | |
head: Node | null = null; | |
append(data: number): 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
type JSONLike = | |
| { [property: string]: JSONLike } | |
| readonly JSONLike[] | |
| string | |
| number | |
| boolean | |
| null; | |
interface Serializable { | |
toJSON(): JSONLike; |
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
import * as React from 'react'; | |
import { useIdle } from 'react-use'; | |
interface Props { | |
timeoutMs: number; | |
children: (data: boolean) => React.ReactElement | null; | |
} | |
const IdleStateRecognition: React.FunctionComponent<Props> = ({ children, timeoutMs }) => { | |
const isIdle = useIdle(timeoutMs); |
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 Dictionary<K, V> { | |
forEach(callbackfn: (value: V, key: K, map: Dictionary<K, V>) => void, thisArg?: any): void; | |
set(key: K, value: V): this; | |
has<T extends K>(key: T): this is { get(key: T): V } & Dictionary<K, V>; | |
has(key: K): boolean; | |
get(key: K): V | undefined; | |
readonly size: number; | |
} | |
interface DictionaryConstructor { |
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 inventory = new Map([ | |
['🍊', 3], | |
['🍌', 1], | |
['🍏', 15], | |
] as const); | |
if (inventory.has('🍊')) { | |
const oranges: number = inventory.get('🍊'); | |
} |