Skip to content

Instantly share code, notes, and snippets.

🎯
Active

Piotrek Witek piotrwitek

🎯
Active
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
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
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
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
// 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
@piotrwitek
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 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 / 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
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
piotrwitek / tslint.json
Last active Apr 20, 2019
TSLint rules with ESLint/React extension based on airbnb style guide
View tslint.json
{
"rules": {
"align": [
true,
"parameters",
"arguments",
"statements"
],
"ban": false,
"class-name": true,
@piotrwitek
piotrwitek / linting-in-typescript-react.md
Last active Mar 10, 2019
Investigation on linting options available for TypeScript & React
View linting-in-typescript-react.md

Recent TSLint v5.0 config

https://github.com/piotrwitek/react-redux-typescript-guide#tslintjson

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

  • TSLint airbnb style guide:
    https://github.com/excelmicro/typescript
  • TSLint React rules:
    https://github.com/palantir/tslint-react
  • Manually add missing airbnb ESLint rules for TSLint:
    https://github.com/buzinas/tslint-eslint-rules
You can’t perform that action at this time.