Skip to content

Instantly share code, notes, and snippets.


Piotrek Witek piotrwitek

Block or report user

Report or block piotrwitek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
piotrwitek / function with an array argument restricted to accept only unique values.ts
Last active Apr 20, 2019
Typing a function with an array argument restricted to accept only unique values
View function with an array argument restricted to accept only unique values.ts
// TS v3.4.3
declare function createTest<TAll>(): <
A extends TAll,
B extends Exclude<TAll, A>,
C extends Exclude<TAll, A | B>,
D extends Exclude<TAll, A | B | C>,
E extends Exclude<TAll, A | B | C | D>
arr: [A] | [A, B] | [A, B, C] | [A, B, C, D] | [A, B, C, D, E]
View curry-variadic.ts
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> =
piotrwitek / download-link-using-blob.tsx
Last active May 27, 2019
create download link for protected resources using blob
View download-link-using-blob.tsx
piotrwitek / interface augmentation typing fun.ts
Created Aug 7, 2017 — 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>
View interface augmentation typing fun.ts
// 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
// - This needs lots of tidying and renaming
// - Do more stuff
piotrwitek / stdlib.ts
Created Aug 2, 2017 — forked from tycho01/stdlib.ts
Type-level standard library for TypeScript
View stdlib.ts
// NOTE: code now moved to
// 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:
export function force<T, V extends T>() {}
piotrwitek / gist:aa6607d3f19f508f58a0912c76c32ef2
Created Jan 14, 2017
Object.assign for type-safe partial state updates
View gist:aa6607d3f19f508f58a0912c76c32ef2
* @export Object.assign for type-safe partial state updates
* @interface ObjectConstructor
export interface ObjectConstructor {
assign<T>(targetState: {}, sourceState: T, ...partialStates: Partial<T>[]): T;
export declare const Object: ObjectConstructor;
piotrwitek / element-animations.ts
Last active Nov 23, 2016
Element animations library for React
View element-animations.ts
// available animations
export const Animations = {
WIGGLE: 'u-anim-wiggle',
const ANIMATION_END = 'animationend';
// HOF for callbacks
export const animateWith = (animation: string) =>
(ev: any) => {
piotrwitek / tslint.json
Last active Apr 20, 2019
TSLint rules with ESLint/React extension based on airbnb style guide
View tslint.json
"rules": {
"align": [
"ban": false,
"class-name": true,
piotrwitek /
Last active Mar 10, 2019
Investigation on linting options available for TypeScript & React

Recent TSLint v5.0 config

Use TSLint with rules based on airbnb style guide and some extensions

  • TSLint airbnb style guide:
  • TSLint React rules:
  • Manually add missing airbnb ESLint rules for TSLint:
You can’t perform that action at this time.