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
function useRunImmediatelyOnChange(effect: () => void, deps: unknown[] = []) { | |
if (!deps.length) deps.push(true); | |
const depsRef = React.useRef<unknown[]>(); | |
if (depsRef.current && depsRef.current.length !== deps.length) { | |
throw new Error("Length of dependency list should not change"); | |
} | |
for (let i = 0; i < deps.length; i += 1) { |
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 Field<T extends Record<string, any> | Array<any>> = Exclude< | |
T extends Array<infer ArrayItem> | |
? | |
| `[${number}]` | |
| (ArrayItem extends Record<string, any> | Array<any> | |
? Field<ArrayItem> extends infer NextValue | |
? NextValue extends string | |
? `[${number}]${NextValue extends `[${string}` ? NextValue : `.${NextValue}`}` | |
: never | |
: never |
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 Person = { | |
name: string; | |
certificate: Record<string, any>; | |
}; | |
// generic usage here is desired, cos it allows the return type to resolve to something more specific | |
function createPerson<T extends Person>(p: T): T { ... } | |
// kyle will have certificate.course typed as "string" | |
const kyle = createPerson({ |
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
/** Overrides properties in the Target */ | |
type Override< | |
Target extends Record<string, unknown>, | |
OverrideWith extends Record<string, unknown> | |
> = Target extends infer Meat & Record<string, any> | |
? Omit<Meat, keyof OverrideWith> & OverrideWith & Record<string, any> | |
: Target extends Record<string, unknown> | |
? Omit<Target, keyof OverrideWith> & OverrideWith | |
: never; |
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 PngQuant from 'pngquant' | |
import { APIGatewayEvent, APIGatewayProxyResult, ScheduledEvent } from 'aws-lambda' | |
import busboy from 'busboy' | |
import { createReadStream, createWriteStream } from 'fs' | |
import { tmpdir } from 'os' | |
import path from 'path' | |
import { Stream } from 'stream' | |
export const handler = async ( | |
event: APIGatewayEvent |