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 LR from 'logrocket'; | |
/** | |
* Fails silently if `LogRocket#init` throws. | |
* | |
* @see https://stackoverflow.com/a/43823282/10325032 | |
*/ | |
export const LogRocket = new Proxy(LR, { | |
get(target, property: keyof typeof LR, receiver) { | |
if (property === 'init') { |
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 React from 'react'; | |
type DeferTypeInference<T> = [T][T extends any ? 0 : never]; | |
interface Props<T extends string> { | |
themeMap: Record<T, any> | |
defaultTheme?: DeferTypeInference<T>; | |
} | |
class ThemeSwitcherProvider<T extends string> extends React.Component<Props<T>> { } |
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
/** | |
* Challenge: given a list of icon names, find icons that exist in sizes 16x16px *and* 24x24px. | |
* This is an AND relationship, not an OR relationship. | |
* | |
* The solution should be: '16-hamburger' | '16-warning' | '24-hamburger' | '24-warning'. | |
*/ | |
type IconName = | |
| '16-hamburger' // 👈🏻 | |
| '16-warning' // 👈🏻 | |
| '16-foo' |
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 { | |
constructor(public namespaces: string[]) { | |
this.namespaces = namespaces; | |
} | |
options = { | |
ns: this.namespaces | |
}; | |
get opts() { |
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 AnyFunction = (...args: any[]) => any; | |
/** | |
* Creates a memoized function that preserves reference equality based on a predicate function. | |
* | |
* @param fn Function which return value will be memoized. | |
* @param isEqual Should return `true` when two objects are considered identical. | |
* | |
* @example | |
* |
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 fs from 'fs'; | |
const promisify = <T>(fn: Promisifiable<T>) => (...args: DropLast<Parameters<typeof fn>>) => | |
new Promise<T>((resolve, reject) => { | |
fn(...args, (err: Error | null, val: T) => (err ? reject(err) : resolve(val))); | |
}); | |
async () => { | |
try { | |
const pkg: Buffer = await promisify(fs.readFile)('package.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
declare global { | |
interface DOMRect extends DOMRectReadOnly { | |
/** | |
* @deprecated Doesn't work on legacy Edge. Use `left` instead. | |
*/ | |
x: number; | |
/** | |
* @deprecated Doesn't work on legacy Edge. Use `right` instead. | |
*/ | |
y: 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 Increments { | |
0: 1; | |
1: 2; | |
2: 3; | |
3: 4; | |
4: 5; | |
} | |
interface Decrements { | |
1: 0; |
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
export function withHover<T>(WrappedComponent: React.ComponentType<T & Hoverable>): React.ComponentClass<T> { | |
return class extends React.Component<T> { | |
state = { | |
hover: false, | |
}; | |
onMouseEnter: React.MouseEventHandler = () => { | |
this.setState({ hover: 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
import { Action, AnyAction, Middleware } from 'redux'; | |
const errorMiddleware: Middleware = | |
store => | |
next => | |
(action: AnyAction) => { | |
if (action.error instanceof Error) { | |
store.dispatch({ | |
type: '@@internal/EXCEPTION_THROWN', | |
payload: action.error.message, |