Skip to content

isObjectOf should accept any object with Object.assign #126

Open
@lambdalisue

Description

@lambdalisue

From #75, isObjectOf accept Function with Object.assign. Additionally, it accept string, number, bigint, boolean, object, and symbol natively. So isObjectOf currently support almost all object except Array like

import { is } from "./mod.ts";

const isMyType = is.ObjectOf({
  a: is.Number,
  b: is.String,
  c: is.Boolean,
});

const myType = { a: 0, b: "a", c: true };
const cases = [
  "string",
  100,
  100n,
  true,
  ["a", "b", "c"],
  {},
  () => {},
  Symbol("symbol"),
];

cases.forEach((c) => {
  const x = Object.assign(c, myType);
  console.log(c, isMyType(x));
});

Only array result become false

string true
100 true
100n true
true true
[ "a", "b", "c", a: 0, b: "a", c: true ] false
{ a: 0, b: "a", c: true } true
[Function (anonymous)] { a: 0, b: "a", c: true } true
Symbol(symbol) true

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions