Skip to content

Instantly share code, notes, and snippets.

@DPros
DPros / reduce.utils.ts
Last active April 3, 2020 09:39
generic reduce wrappers
export function toObject<T>(entries: [string, T][]): Record<string, T>;
export function toObject<T>(entries: [keyof T, T[keyof T]][]) {
return entries.reduce((object, [key, value]) => {
object[key] = value;
return object;
}, {} as T);
}
export function toDictionary<T, K extends keyof T>(objects: T[], keySelector: K | ((object: T) => string)) {
return objects.reduce((dictionary, object) => {
@DPros
DPros / typed-form.ts
Last active April 3, 2020 15:10
Angular Typed
// tslint:disable:max-classes-per-file
import {
AbstractControl,
AbstractControlOptions,
AsyncValidatorFn,
FormArray,
FormControl,
FormGroup,
ValidatorFn,
} from "@angular/forms";