Skip to content

Instantly share code, notes, and snippets.

View piotrwitek's full-sized avatar

Piotr Witek piotrwitek

View GitHub Profile
@piotrwitek
piotrwitek / stdlib.ts
Created August 2, 2017 22:04 — forked from KiaraGrouwstra/stdlib.ts
Type-level standard library for TypeScript
// NOTE: code now moved to https://github.com/tycho01/typical
// older revision left here, but it no longer runs well in TS Playground
export type Obj<T> = { [k: string]: T };
export type NumObj<T> = { [k: number]: T };
// export type List = ArrayLike; // no unapplied generic types :(
export type List<T> = ArrayLike<T>;
// progress: https://github.com/Microsoft/TypeScript/issues/16392
export function force<T, V extends T>() {}
@piotrwitek
piotrwitek / interface augmentation typing fun.ts
Created August 7, 2017 19:38 — forked from SamPruden/interface augmentation typing fun.ts
Messing around with a trick that allows basic type switching in TypeScript, and provides the ability to make DeepReadonly<T>
// WHAT IS THIS?
// This is me playing around with a cool (but dirty) trick
// Some interfaces can be globally augmented to provide info to the type system
// This then allows some basic type switch and retrieval operations
// I needed a DeepReadonly<T> for a thing, I think I have it now
// Built/tested in 2.5.0-dev20170803
// FUTURE PLANS
// - This needs lots of tidying and renaming
// - Do more stuff
type Init<T extends any[], TTail extends any[] = TailArray<T>> = CastArray<{
[K in keyof TTail]: T[keyof T & K];
}>
type PotentialArgs<T extends any[], TResult extends any[] = T> = {
"continue": PotentialArgs<Init<T>, TResult | Init<T>>;
"end": TResult;
}[T extends [] ? "end" : "continue"]
type Args<T extends Function> =