Ts-toolbelt: Pick method also includes all of the optional parameters

Created on 4 Aug 2019  路  3Comments  路  Source: millsp/ts-toolbelt

馃悶 Bug Report

Describe the bug

When using a Pick method on a type that contains optional parameters the resulting type will contain all of those optional parameters regardless of what the path argument is.

Reproduce the bug

interface Test {
  foo: string;
  bar?: string;
}

type pickedTest = O.P.Pick<Test, ['foo']>;

pickedTest contains foo and optional bar property.

Expected behavior

Type pickedTest contains only foo property.

Additional context

I want to use it to type GraphQL queries and excluding certain properties is critical for building the returned object type correctly.

bug

Most helpful comment

Thanks for reporting this. I will start fixing this tomorrow.

All 3 comments

Thanks for reporting this. I will start fixing this tomorrow.

Fixed. Let me know if it's all good.

I added tests to make sure there's no regression. And added docs for Object.P.

Happy coding!

Thanks for quick response and a fix! Seems to be working correctly.
Although, I've got a new question about how to pick two different paths of an object that have different subobject names and if that is even possible. I'll file a new ticket for that.

Was this page helpful?
0 / 5 - 0 ratings