Fix lodash.isFunction typings#21015
Fix lodash.isFunction typings#21015DanielRosenwasser merged 6 commits intoDefinitelyTyped:masterfrom
Conversation
|
types/lodash/index.d.ts to authors (@bczengel @chrootsu @stepancar @ericanderson @aj-r @Ailrun @e-cloud @thorn0). Could you review this PR? |
|
@unional Please fix the failures indicated in the Travis CI log. |
|
@aj-r I think I was wrong and we should keep |
|
#21015 is a stop-gap for microsoft/TypeScript#19480 Fixing that does means we lost the Would need some input. (It is so hard to do PR on DT, and no movement on microsoft/types-publisher#4) |
|
The problem with |
|
You can call a declare var a: Function;
a(10, 20);But you can't call a declare var a: Function | ((...args: any[]) => any)
a(10, 20);The question is which of the two parts of the union should stay in the type guard. The problem with So far my conclusion is that the type guard should be On the other hand, @aj-r might have had some extra considerations in mind when he added |
|
I was trying to replace I did some more testing just now, and it looks like if we remove I don't think this is a huge problem. If anything, we should be forcing people to stop using Whichever route we take, we should add this test to |
types/lodash/index.d.ts
Outdated
| * @return Returns true if value is correctly classified, else false. | ||
| */ | ||
| isFunction(value?: any): value is ((...args: any[]) => any) | Function; | ||
| isFunction(value?: any): value is (...args: any[]) => any; |
There was a problem hiding this comment.
I think we should make the parameter non-optional (remove the ?).
Also don't forget to fix lodash-tests.ts. Probably change let result: number = value; to let result: number | Function = value;, and add the test case I mentioned in my other comment.
You can test that your changes are working by running npm run lint lodash
|
@unional Please fix the failures indicated in the Travis CI log. |
I cannot get the lint to run Working on DT is now too complex and frustrating. When will microsoft/types-publisher#4 be worked on? There is no reason to download the whole DT repo just to make a change to one package. |
|
More detail on the error: Installing to /Users/hwong/github/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/typescript-installs/next...
Installed!
Error: Unexpected tag kind: JSDocTypeLiteral
at checkTag (/Users/hwong/github/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/bin/rules/noRedundantJsdoc2Rule.js:95:23)
at cb (/Users/hwong/github/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/bin/rules/noRedundantJsdoc2Rule.js:47:25)
at visitNodes (/Users/hwong/github/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/node_modules/typescript/lib/typescript.js:12652:30)
at Object.forEachChild (/Users/hwong/github/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/node_modules/typescript/lib/typescript.js:12910:21)
at cb (/Users/hwong/github/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/bin/rules/noRedundantJsdoc2Rule.js:52:19)
at visitNodes (/Users/hwong/github/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/node_modules/typescript/lib/typescript.js:12652:30)
at Object.forEachChild (/Users/hwong/github/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/node_modules/typescript/lib/typescript.js:12828:24)
at cb (/Users/hwong/github/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/bin/rules/noRedundantJsdoc2Rule.js:52:19)
at visitNode (/Users/hwong/github/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/node_modules/typescript/lib/typescript.js:12643:24)
at Object.forEachChild (/Users/hwong/github/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/node_modules/typescript/lib/typescript.js:12929:21)
Error: /Users/hwong/github/DefinitelyTyped/DefinitelyTyped/types/lodash/lodash-tests.ts
ERROR: 8063:17 expect TypeScript@next compile error:
Type 'Function' is not assignable to type 'number'.
at /Users/hwong/github/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/bin/index.js:76:19
at Generator.next (<anonymous>)
at fulfilled (/Users/hwong/github/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/bin/index.js:5:58)
at <anonymous> |
|
npm@5 doesn't work with node@9. |
|
Approved by a listed owner. PR ready to merge pending express review by a maintainer. |
| } | ||
|
|
||
| if (_.isFunction(any)) { | ||
| any(); |
There was a problem hiding this comment.
What is the point of this test? Type guards don't narrow down any.
|
Yes they do. This test would have failed before this fix was implemented.
|
|
Yep, sorry, I was wrong. |
The change fix the following case:
microsoft/TypeScript#19480