Skip to content

Instantly share code, notes, and snippets.

View piotrwitek's full-sized avatar

Piotr Witek piotrwitek

View GitHub Profile
@piotrwitek
piotrwitek / linting-in-typescript-react.md
Last active March 10, 2019 23:49
Investigation on linting options available for TypeScript & React

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
@piotrwitek
piotrwitek / tslint.json
Last active April 20, 2019 01:18
TSLint rules with ESLint/React extension based on airbnb style guide
{
"rules": {
"align": [
true,
"parameters",
"arguments",
"statements"
],
"ban": false,
"class-name": true,
@piotrwitek
piotrwitek / element-animations.ts
Last active November 23, 2016 00:12
Element animations library for React
// 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 / gist:aa6607d3f19f508f58a0912c76c32ef2
Created January 14, 2017 16:51
Object.assign for type-safe partial state updates
/**
* @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 / 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
@piotrwitek
piotrwitek / download-link-using-blob.tsx
Last active May 27, 2019 20:54
create download link for protected resources using blob
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 / function with an array argument restricted to accept only unique values.ts
Last active April 20, 2019 12:33
Typing a function with an array argument restricted to accept only unique values
// 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]
// delegatorPublicKey: string, // 02024ef1def792992eeed81b2c55c42420236700b9c0eb55229cfd31a5e1ef437ac4
// validatorPublicKey: string, // 017d96b9a63abcb61c870a4f55187a0a7ac24096bdb5fc585c12a686a4d892009e
// delegateAmount: BigNumber,
const delegatorPublicKey = PublicKey.fromHex(publicKeyHex);
const validatorPublicKey = PublicKey.fromHex(validatorHex);
const args = RuntimeArgs.fromMap({
delegator: CLValue.publicKey(delegatorPublicKey),
validator: CLValue.publicKey(validatorPublicKey),