Skip to content

_.pick vs TypeScript's Pick #5984

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

Open
twiddler opened this issue Apr 25, 2025 · 0 comments
Open

_.pick vs TypeScript's Pick #5984

twiddler opened this issue Apr 25, 2025 · 0 comments

Comments

@twiddler
Copy link

twiddler commented Apr 25, 2025

I expected pick to agree with TypeScript's Pick, but it does not:

import { pick } from 'lodash';
import { test } from 'vitest';

// ✅
test('Pick', function () {
  type a = Pick<
    { foo: number },
    // @ts-expect-error Should prevent picking missing properties
    'bar'
  >;

  // @ts-expect-error Non-picked properties should not exist
  type b = a['foo'];
});

// ❌
test('pick', function () {
  const p = pick({ foo: 1 }, [
    // @ts-expect-error Should prevent picking missing properties
    'bar', // ❌ Does not cause a type error
  ]);

  // @ts-expect-error Non-picked properties should not exist
  p.foo === 1; // ❌ Does not cause a type error
});

Also see index.test-d.ts in this codesandbox.

Is the aim of pick to agree with Pick?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant