Skip to main content
Module

x/typestruct/mod.ts>pick

Composable and checkable JavaScript (and TypeScript) data structure
Latest
function pick
import { pick } from "https://deno.land/x/typestruct@1.0.0-beta.5/mod.ts";

Create Pick struct. From struct, pick a set of properties whose keys are in the definition.

Examples

Example 1

import {
  is,
  object,
  pick,
  string,
} from "https://deno.land/x/typestruct@$VERSION/mod.ts";
import { assertEquals } from "https://deno.land/std@$VERSION/testing/asserts.ts";

const User = object({ id: string(), name: string() });
const data = { name: "tom" };

assertEquals(is(User, data), false);
assertEquals(is(pick(User, ["name"]), data), true);

Type Parameters

U extends StructMap
K extends keyof U

Parameters

struct: Struct<unknown, U> & Definable<U>

Definable struct.

keys: Iterable<K>

Pick properties.

Returns

Struct<unknown, Pick<U, K>> & Definable<Pick<U, K>>