UNPKG

rivo

Version:

🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.

49 lines (45 loc) • 1.67 kB
// @ts-ignore - Only used in doc comments import type { Pick } from "./Pick"; // @ts-ignore - Only used in doc comments import type PickFn from "./Pick"; import type { Args, GenericFn, GenericResolver } from "../HKT"; import type { Eq, IsPropertyKeyLiteral } from "../helpers"; /** * Less strict version of {@link Pick}.The **W** suffix (short for **W**idening) means that the key * type is widened to `PropertyKey`. * * Sig: `(k: PropertyKey, o: object) => object` */ // We do not use the built-in `Pick` type because it does not keep the readonly modifier. export type PickW<K extends PropertyKey, O> = { [P in keyof O as P extends K ? P : never]: O[P]; }; interface Resolver extends GenericResolver<[PropertyKey, object], object> { on1_: ([k]: Args<this>) => [[object], object]; on_1: ([, o]: Args<this>) => [[PropertyKey], object]; on11: ([k, o]: Args<this>) => [ [], IsPropertyKeyLiteral<typeof k> extends true ? { [P in keyof typeof o as P extends typeof k ? P : never]: (typeof o)[P] } extends infer R ? Eq<R, typeof o> extends true ? typeof o : R : never : { readonly [P in typeof k]: (typeof o)[keyof typeof o] } extends infer R ? Eq<R, typeof o> extends true ? typeof o : R : never, ]; } /** * [Fn] Less strict version of {@link Omit}.The **W** suffix (short for **W**idening) means that the * key type is widened to `PropertyKey`. * * Sig: `(k: PropertyKey, o: object) => object` */ export default interface PickWFn extends GenericFn<Resolver> { def: ([k, o]: Args<this>) => { [P in keyof typeof o as P extends typeof k ? P : never]: (typeof o)[P]; }; }