type StringBool = "true"|"false";
interface AnyNumber { prev?: any, isZero: StringBool };
interface PositiveNumber { prev: any, isZero: "false" };
type IsZero<TNumber extends AnyNumber> = TNumber["isZero"];
type Next<TNumber extends AnyNumber> = { prev: TNumber, isZero: "false" };
type Prev<TNumber extends PositiveNumber> = TNumber["prev"];
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 token = | |
| INT of int | |
| IDENTIFIER of string | |
| PLUS | |
| MINUS | |
| TIMES | |
| DIV | |
| LET | |
| ASSIGN | |
| EQ |
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 Iterate<T extends number, A extends number[] = []> = A["length"] extends T | |
? A | |
: Iterate<T, [...A, A["length"]]>; | |
type StrictlyLonger<A extends any[], B extends any[]> = A extends [ | |
any, | |
...infer ATail | |
] | |
? B extends [any, ...infer BTail] | |
? StrictlyLonger<ATail, BTail> |
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
/** | |
* `Record<Keys, Type>` | |
* | |
* Constructs an object type whose property keys are Keys and whose property values are Type. This utility can be used to map the properties of a type to another type. | |
* | |
* https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type | |
*/ | |
type _Record<K extends string | number | symbol, T> = { | |
[P in K]: 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
import { default as player } from "play-sound"; | |
const play = (name: string) => player().play(`./assets/${name}.wav`); | |
const sleep = (time: number) => { | |
return new Promise((res) => | |
setTimeout(() => { | |
res(null); | |
}, time) | |
); | |
}; |
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
class None {} | |
class Some<T> { | |
constructor(public value: T) {} | |
} | |
type Maybe<T> = None | Some<T>; | |
export const none = new None(); |
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
interface Observer<T> { | |
next: (el: T) => void; | |
} | |
type Dispose = () => void; | |
type Operator<T, U> = (source$: Observable<T>) => Observable<U> | |
class Observable<T> { | |
constructor(private cb: (observer: Observer<T>) => Dispose) {} |
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 { useCallback, useEffect, useReducer, useRef } from "react"; | |
type Comparator = (value1: any, value2: any) => boolean; | |
/** Core */ | |
type Listener = () => void; | |
type Destroy = () => void; |
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 { useEffect, useReducer, useMemo } from "react"; | |
import { BehaviorSubject } from "rxjs"; | |
export const createStateHook = <S>(init: S) => { | |
const state$ = new BehaviorSubject(init); | |
const setState = (change: S | ((state: S) => S)) => { | |
state$.next(change instanceof Function ? change(state$.value) : change); | |
}; |
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 IFlattenable<K extends string> = { | |
[k in K]?: IFlattenable<K>[]; | |
} & { id: number }; | |
type IFlattened<T extends IFlattenable<K>, K extends string> = Omit< | |
T, | |
K | 'id' | |
> & { | |
parentId: number; | |
id: number; |
NewerOlder