smart-types-ts
Version:
A collection of _Smart Types_ and _Smart Constructors_ which enable you to be more strict when defining your application's important types/interfaces.
11 lines (8 loc) • 329 B
text/typescript
import { flow } from "fp-ts/lib/function";
import * as e from "fp-ts/lib/Either";
import { SmartConstructor, SmartType } from "../utilTypes";
export type Int = SmartType<number, "Integer">;
export const mkInt: SmartConstructor<Int> = flow(
e.fromPredicate(Number.isInteger, () => "Not an integer"),
e.map(x => x as Int)
);