Skip to content

Instantly share code, notes, and snippets.

Chappo lukeggchapman

  • Sydney, Australia
Block or report user

Report or block lukeggchapman

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
@lukeggchapman
lukeggchapman / mapObj.ts
Created Sep 5, 2019
Typescript map object
View mapObj.ts
// Like array.map, but for objects
const mapObj = <U, T extends object>(
obj: T,
mapFn: (val: T[keyof T], key?: keyof T) => U
): { [K in keyof T]: U } => {
return Object.assign(
{},
...Object.entries(obj).map(([k, v]) => ({ [k]: mapFn(v, k as keyof T) }))
);
};
@lukeggchapman
lukeggchapman / promiseAllObj.ts
Created Sep 3, 2019
Typescript promiseAllObj. Like Promise.all but for objects. Similar to bluebird.props.
View promiseAllObj.ts
// Like Promise.all, but for objects of {key: Promise}
const promsieAllObj = async <T>(obj: Record<string, Promise<T>>): Promise<Record<string, T>> => {
const arr = Object.entries(obj).map(([key, value]) => value.then(res => [key, res]));
return Object.assign(
{},
...(await Promise.all(arr).then(res => res.map(([k, v]) => ({ [k as string]: v as T }))))
);
};
@lukeggchapman
lukeggchapman / typescriptreact.json
Created Apr 28, 2019
Typescript + react snippets
View typescriptreact.json
{
"React Component": {
"prefix": "rcc",
"body": [
"import * as React from 'react'",
"",
"export interface ${1:IApp}Props {",
" ${2:}",
"}",
"",
You can’t perform that action at this time.