Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isObjectOf should accept any object with Object.assign #126

Open
lambdalisue opened this issue Aug 14, 2024 · 1 comment
Open

isObjectOf should accept any object with Object.assign #126

lambdalisue opened this issue Aug 14, 2024 · 1 comment
Labels
breaking enhancement New feature or request
Milestone

Comments

@lambdalisue
Copy link
Member

lambdalisue commented Aug 14, 2024

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
@lambdalisue lambdalisue changed the title RFC: isObjectOf should not exclude array RFC: isObjectOf should accept any object with Object.assign Aug 14, 2024
@lambdalisue lambdalisue added enhancement New feature or request breaking labels Aug 14, 2024
@lambdalisue lambdalisue added this to the v5 milestone Aug 21, 2024
@lambdalisue lambdalisue changed the title RFC: isObjectOf should accept any object with Object.assign isObjectOf should accept any object with Object.assign Aug 21, 2024
@lambdalisue
Copy link
Member Author

This is a breaking change so I've applied it for v5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant