denoland / denoland/std

bug(collection): Inconsistent behavior between `pick` and `omit`

Open
#5,966 0 comments 0 reactions 0 assignees View on GitHub
bug needs triage
Dominant language
TypeScript
Stars
3.6k
Forks
681
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**

Found on https://github.com/denoland/std/pull/5926#discussion_r1751285539

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

```ts
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 https://github.com/denoland/std/issues/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:

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.