optix
Version:
Optix is a data manipulation library that provides optics-like capabilites with a simpler syntax. It features robust Typescript support with minimal type annotations and is smaller and faster than true optics libraries.
9 lines (8 loc) • 714 B
TypeScript
import { BuildTypeFromPath, BuildTypeFromPathOptional, GetTypeAtPath, MergeRightWthDepth, PartialIfObject, PathItem } from "./common";
export interface Set {
<Keys extends readonly [PathItem, ...PathItem[]]>(...keys: Keys): <U>(update: U) => <T extends BuildTypeFromPathOptional<PartialIfObject<U>, Keys>>(obj: T) => U extends GetTypeAtPath<T, Keys> ? T : unknown;
}
export interface PolySet {
<Keys extends readonly [PathItem, ...PathItem[]]>(...keys: Keys): <U>(update: U) => <T>(obj: T) => Keys extends [infer _, ...infer Rest] ? MergeRightWthDepth<T, BuildTypeFromPath<PartialIfObject<U>, Keys>, Rest> : U;
}
export declare type _Set = <T>(obj: T, path: readonly PathItem[], update: any) => T;