Skip to main content
Module

x/typeguardkit/mod.ts>PickAsserter

A TypeScript module to help construct type assertion functions and type guards.
Latest
class PickAsserter
Re-export
import { PickAsserter } from "https://deno.land/x/typeguardkit@0.32.1/mod.ts";

A PickAsserter is an ObjectAsserter for the type constructed by picking the set of properties Keys from the asserted type of the provided ObjectAsserter.

Example:

import {
  _string,
  Asserted,
  ObjectAsserter,
  PickAsserter,
} from "typeguardkit";

// types/user.ts

export const _User = new ObjectAsserter("User", {
  id: _string,
  firstName: _string,
  lastName: _string,
});

export type User = Asserted<typeof _User>;

// types/user_name.ts

export const _UserName = new PickAsserter(
  "UserName",
  _User,
  ["firstName", "lastName"],
);

export type UserName = Asserted<typeof _UserName>;

Constructors

new
PickAsserter(
typeName: string,
keys: Keys,
)

Type Parameters

PropertyAsserters extends Record<string, Asserter<unknown>>
Keys extends Array<keyof PropertyAsserters>