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
type NonEmptyArray<T> = [T, ...T[]] |
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
// @see https://stackoverflow.com/questions/60449479/typescript-extract-type-from-object-by-object-path-in-tuple | |
type ExtractType<O, T extends Array<any>> = { | |
[K in keyof O]: ((...a: T) => any) extends (a: any, ...args: infer Tail) => any | |
? Tail['length'] extends 0 | |
? O[K] | |
: ExtractType<O[K], Tail> | |
: never | |
}[T[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
type Writeable<T> = { | |
-readonly [Key in keyof T]: T[Key] | |
} | |
type DeepWriteable<T> = { | |
-readonly [Key in keyof T]: DeepWriteable<T[Key]> | |
} |
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
type UnionToType< | |
U extends Record<string, unknown> | |
> = { | |
[K in (U extends unknown ? keyof U : never)]: U extends unknown | |
? K extends keyof U ? U[K] : never | |
: never | |
} | |
type A = { | |
a: string |
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
/** | |
* Checks if type `T` is the `any` type. | |
* @see https://stackoverflow.com/a/49928360/3406963 | |
* @see https://github.com/dsherret/conditional-type-checks/blob/main/mod.ts | |
*/ | |
type IsAny<T> = 0 extends 1 & T ? true : false | |
type Example<S> = IsAny<S> extends false ? 'ok' : never | |
/** |
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
export const useEffectOnce = (effect: EffectCallback) => { | |
const destroyFunc = useRef<ReturnType<EffectCallback>>() | |
const calledOnce = useRef(false) | |
const renderAfterCalled = useRef(false) | |
if (calledOnce.current) { | |
renderAfterCalled.current = true | |
} | |
useEffect(() => { |
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
const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
const MIN_RADIX = 2 | |
const MAX_RADIX = ALPHABET.length | |
function chekRadix(radix: number): void { | |
if (radix < MIN_RADIX || radix > MAX_RADIX) { | |
throw new Error(`radix argument must be between ${MIN_RADIX} and ${MAX_RADIX}`) | |
} | |
} |
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
import { FlightSearchStep, getNextStep, getPrevStep, SeatType } from './index' | |
const VALID_STEPS_MAP: { | |
[key: string]: { | |
[key: string]: { | |
prev: FlightSearchStep | undefined | |
next: FlightSearchStep | undefined | |
} | |
} | |
} = { |
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
import type { MutableRefObject } from 'react' | |
import { useRef } from 'react' | |
const noop = {} | |
export function useLazyRef<T>(init: () => T) { | |
const ref = useRef<T | typeof noop>(noop) | |
if (ref.current === noop) { | |
ref.current = init() |
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
import * as React from 'react' | |
import { useSelector } from 'react-redux' | |
import type { OutputSelector, OutputParametricSelector } from 'redux-views' | |
type SelectorWithIdAndUse = (OutputSelector<any, any, any> | OutputParametricSelector<any, any, any, any>) & { | |
use?: (...args: any[]) => any | |
idSelector?: (...args: any[]) => any | |
} | |
export const usePropsSelector = <T extends SelectorWithIdAndUse = SelectorWithIdAndUse>( |