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 {}; | |
// https://gist.github.com/rattrayalex/b85d99d4428ee9c1f51661af324c767b | |
type SchemaPrimitive = | |
| { | |
type: "integer"; | |
} | |
| { | |
type: "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
declare const test1: {} | |
declare const test2: {foo: 1} | |
declare const test3: {foo: 1,asda:11} | |
declare const assertRecordIsEmpty:(input: Record<keyof any,never>) => void | |
assertRecordIsEmpty(test1) | |
assertRecordIsEmpty(test2) | |
assertRecordIsEmpty(test3) |
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 pascalCaseToKebabCase = (x: string) => | |
x.replace( | |
/[A-Z]/g, | |
(match, offset) => (offset > 0 ? "-" : "") + match.toLowerCase() | |
); | |
const kebabCaseToPascalCase = (x: string) => | |
x | |
.replace(/(^[a-z])|(-[a-z])/g, (match) => match.toUpperCase()) |
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 { Duplex, ReadableOptions } from "stream"; | |
export const createDeferredPromise = <T>() => { | |
const res = { | |
resolve: (_val: T) => {}, | |
reject: (_reason?: unknown) => {}, | |
promise: new Promise<T>((resolve, reject) => { | |
res.resolve = resolve; | |
res.reject = reject; | |
}), | |
}; |
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 representing a guard function accepting Input and some other arguments | |
* while refining type of input as `Output` | |
*/ | |
export type TypeGuard< | |
Input, | |
Output extends Input, | |
Args extends unknown[] = [] | |
> = (value: Input, ...args: Args) => value is Output; |
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
enum Bool {True="t", False="f"} | |
function f(b:Bool) { | |
switch(b) { | |
case Bool.True: return 'true' | |
case Bool.False: return 'false' | |
// ERROR AS EXPECTED ✅ | |
case "11": return 'oops' | |
// ERROR AS EXPECTED ✅ | |
case 11: return 'oops' |
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
let zz: {} | |
zz = {} // COMPILES | |
zz = 1 // COMPILES | |
zz = "1" // COMPILES | |
zz = true // COMPILES | |
zz = { ff:true } // COMPILES | |
zz = [11] // COMPILES | |
zz = [] // COMPILES |
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 fc from "fast-check"; | |
import { pipe } from "fp-ts/lib/function"; | |
import { | |
fromArray, | |
groupSort, | |
map, | |
NonEmptyArray, | |
} from "fp-ts/lib/NonEmptyArray"; | |
import { Ord, ordDate, ordNumber } from "fp-ts/lib/Ord"; | |
import { |
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 { Semaphore } from "async-mutex"; | |
import util from "util"; | |
import path from "path"; | |
import id3 from "node-id3"; | |
import http from "http"; | |
import fs from "fs"; | |
import { Tags } from "node-id3"; | |
import { assert, assert_, notNullOrUndefined } from "../lib/assert"; | |
const work = { |
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 { Mutex } from "async-mutex"; | |
export type MVar<T> = { | |
take: () => Promise<T>; | |
read: () => Promise<T>; | |
put: (newVal: T) => Promise<void>; | |
}; | |
export const newMVar = function <T>(initial: T): MVar<T> { | |
const val = { current: initial }; |
NewerOlder