-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Lodash omit unset #25522
Lodash omit unset #25522
Conversation
Also added some better tests.
@aj-r Thank you for submitting this PR! 🔔 @bczengel @chrootsu @stepancar @Ailrun @e-cloud @thorn0 @jtmthf @DomiR @typicode @niieani - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
@aj-r The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
@aj-r The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
@aj-r I haven't seen anything from you in a while and this PR currently has problems that prevent it from being merged. The PR will be closed tomorrow if there aren't new commits to fix the issues. |
@aj-r The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I needed to trim down the tests a bunch, otherwise the build fails due to lack of memory. This happens even without the changes from this PR, so I think it's caused by some change in TS 2.9.
Anyway, trimming down the tests make this PR a bit hard to read, so I've tried to highlight the significant changes to lodash-tests.ts
. All changes in other files (common.d.ts
, object.d.ts
, fp.d.ts
, generate-fp.ts`) are significant as well.
@@ -2860,15 +2860,23 @@ declare module "../index" { | |||
*/ | |||
omit<T extends AnyKindOfDictionary>( | |||
object: T | null | undefined, | |||
...paths: PropertyPath[] | |||
...paths: Array<Many<PropertyName>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type is technically the same as before, but I thought Many<PropertyName>
better reflected how the value is being used.
@@ -5396,7 +5161,7 @@ fp.now(); // $ExpectType number | |||
|
|||
_.chain("abc").get(1); // $ExpectType LoDashExplicitWrapper<string> | |||
_.chain("abc").get(["0"], "_"); | |||
_.chain([42]).get(0, -1); // $ExpectType LoDashExplicitWrapper<number | undefined> | |||
_.chain([42]).get(0, -1); // ExpectType LoDashExplicitWrapper<number> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was failing even on the default branch (probably due to a bug fix in TS2.9) so I had to disable the $ExpectType
.
@@ -5788,24 +5538,24 @@ fp.now(); // $ExpectType number | |||
const dictionary: _.Dictionary<AbcObject> = anything; | |||
const numericDictionary: _.NumericDictionary<AbcObject> = anything; | |||
|
|||
_.omit(obj, "a"); // $ExpectType Partial<AbcObject> | |||
_.omit(obj, "a"); // ExpectType Pick<AbcObject, "b" | "c"> // NOTE: ExpectType disabled because it fails in TS2.4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test the new omit
overload
fp.unset("a.b")(object); // $ExpectType boolean | ||
fp.unset(["a", "b"])(object); // $ExpectType boolean | ||
|
||
fp.unset("a.b", object); // $ExpectType { a: { b: string; c: boolean; }; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FP's version of unset
returns an object, not a boolean.
_.propertyOf({}); // $ExpectType (path: Many<PropertyName>) => any | ||
_({}).propertyOf(); // $ExpectType LoDashImplicitWrapper<(path: Many<PropertyName>) => any> | ||
_.chain({}).propertyOf(); // $ExpectType LoDashExplicitWrapper<(path: Many<PropertyName>) => any> | ||
_.propertyOf({}) as (path: _.Many<_.PropertyName>) => any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests were also failing on the default branch - looks like TS 2.9 splits PropertyName
into string | number | symbol
, but earlier versions do not, so the $ExpectType
does not work in this case.
A definition owner has approved this PR ⭐️. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me.
Thanks for the contribution! |
Fixes #25382, fixes #25361, fixes #25365. See discussion in those bugs.
Also fixes incorrect FP types for the
partial
function.Please fill in this template.
npm test
.)npm run lint package-name
(ortsc
if notslint.json
is present).If changing an existing definition:
tslint.json
containing{ "extends": "dtslint/dt.json" }
.