Skip to content

bug(collection): Inconsistent behavior between pick and omit #5966

Open
@lambdalisue

Description

@lambdalisue

Describe the bug

Found on #5926 (comment)

The code below throws a runtime error on o.foo() but type errors.

import { pick } from "jsr:@std/collections/pick";
import { omit } from "jsr:@std/collections/omit";

class A {
  constructor(public a: string, public b: string, public c: string) {}

  foo(): string {
    return "hello";
  }
}

const obj = new A("a", "b", "c");

const p = pick(obj, ["a", "c", "foo"]);
const o = omit(obj, ["b"]);

console.log(obj.foo());
console.log(p.foo());
console.log(o.foo());

Closely related to #5927

Steps to Reproduce

Expected behavior

While the code doesn't throw type error, we should keep non listed methods in omit (o.foo() should be available.)

Environment

  • OS: [e.g. Ubuntu 20.04, MacOS 11]
  • deno version:
  • std version:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions