{"action":"closed","number":4791,"pull_request":{"url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/pulls/4791","id":38990380,"html_url":"https://github.com/borisyankov/DefinitelyTyped/pull/4791","diff_url":"https://github.com/borisyankov/DefinitelyTyped/pull/4791.diff","patch_url":"https://github.com/borisyankov/DefinitelyTyped/pull/4791.patch","issue_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/issues/4791","number":4791,"state":"closed","locked":false,"title":"Fix the very broken lodash flatten() type definitions","user":{"login":"pimterry","id":1526883,"avatar_url":"https://avatars.githubusercontent.com/u/1526883?v=3","gravatar_id":"","url":"https://api.github.com/users/pimterry","html_url":"https://github.com/pimterry","followers_url":"https://api.github.com/users/pimterry/followers","following_url":"https://api.github.com/users/pimterry/following{/other_user}","gists_url":"https://api.github.com/users/pimterry/gists{/gist_id}","starred_url":"https://api.github.com/users/pimterry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pimterry/subscriptions","organizations_url":"https://api.github.com/users/pimterry/orgs","repos_url":"https://api.github.com/users/pimterry/repos","events_url":"https://api.github.com/users/pimterry/events{/privacy}","received_events_url":"https://api.github.com/users/pimterry/received_events","type":"User","site_admin":false},"body":"The current lodash flatten type definitions:\r\n\r\n* Include method overloads that don't actually exist (in lodash or underscore or anywhere else I can find. My best guess is these were copied from _.map() and _.filter() accidentally somehow). You cannot pass a string to flatten() to pluck fields, or a callback to filter things, but we do currently have definitions for those overloads anyway\r\n\r\n* Have tests that specific the wrong expected types (along with a broken implementation to match):\r\n\r\n  The test for `_.flatten([1, [2], [3, [[4]]]])` expects a return type number\\[\\] (and gets it), but the actual return value of that expression is `[1, 2, 3, [[4]]]`, which is not a number[].\r\n\r\n* Have overly specific types that exclude the real resulting type in most cases:\r\n\r\n  `_([1, 2, 3]).flatten()` returns a lodash-wrapped `[1, 2, 3]`, and has type `LodashArrayWrapper<number>` which is correct (i.e. it works correctly, if you call flatten on an already-flattened array).\r\n  `_([[1, 2, 3]]).flatten()` returns a lodash-wrapped `[1, 2, 3]` with type `LodashArrayWrapper<Array<number>>` (incorrect, for the normal case).\r\n\r\nThis patch fixes those, conveniently fixing #2835 en route, although there are a couple of parts worthy of a little debate I think (see below). The changes are:\r\n\r\n* Type definitions for non-existent `_.flatten()` and `_().flatten()` methods overloads have been removed.\r\n\r\n* `_(array).flatten()` and `_(array).flatten(bool)` now both return `any`, rather than the overly specific (and usually wrong) type there before. Being any more specific than this is possible I think, but requires some heavy duty work around the generics for LoDashArrayWrapper everywhere to get to something like `LoDashArrayWrapper<X, T extends RecursiveList<X>> { flatten(array: T): LoDashArrayWrapper<???, X> }`. Not sure that's practical, so I've at least made it work for now.\r\n\r\n* _.flatten(array) now has the correct type and matching tests that actually track the real behaviour\r\n\r\n* _.flatten(array, bool) is now more accurate, but not always (although that's still an improvement on the current state). I'm not sure if this can be better, or whether it's worthwhile investigating that further.\r\n  \r\n  The issue is that the type of the result depends on the value of the boolean 2nd argument:\r\n\r\n  `_.flatten([[[1]]], true)` recursively flattens, and returns `[1]`. This has type `(number[][][]) => number[]`, or generally `(RecursiveList<T>) => T`. This is the type that I've given the method.\r\n\r\n  `_.flatten([[[1]]], false)` meanwhile is equivalent to `_.flatten([[[1]]])`, and recurses only one level, returning `[[1]]`, so here has a type of `(number[][][]) => number[][]`. This doesn't match the type definition. On the other hand, this is definitely the unusual case for this method (since the 'false' is unnecessary), and falling back to the version without the extra argument will give you the correct type.\r\n\r\n  How concerned is DefinitelyTyped generally about things like this? Any thoughts on how this bit could be improved? Perfect world would be to use the correct return type depending on the runtime boolean value of the flag whenever that's known (likely 99+% of the time), but I think that's impossible. Option C is to just make it any-typed, but I'd rather not if at all possible.","created_at":"2015-07-01T14:53:37Z","updated_at":"2015-07-14T16:44:35Z","closed_at":"2015-07-14T16:44:35Z","merged_at":"2015-07-14T16:44:35Z","merge_commit_sha":"af3be96ff972b6cd47b2f1a8a4b835d09d1221f4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/pulls/4791/commits","review_comments_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/pulls/4791/comments","review_comment_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/pulls/comments{/number}","comments_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/issues/4791/comments","statuses_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/statuses/ed15e4bd3806d00223f40803a7d13d0d3ada111e","head":{"label":"pimterry:lodash-flatten","ref":"lodash-flatten","sha":"ed15e4bd3806d00223f40803a7d13d0d3ada111e","user":{"login":"pimterry","id":1526883,"avatar_url":"https://avatars.githubusercontent.com/u/1526883?v=3","gravatar_id":"","url":"https://api.github.com/users/pimterry","html_url":"https://github.com/pimterry","followers_url":"https://api.github.com/users/pimterry/followers","following_url":"https://api.github.com/users/pimterry/following{/other_user}","gists_url":"https://api.github.com/users/pimterry/gists{/gist_id}","starred_url":"https://api.github.com/users/pimterry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pimterry/subscriptions","organizations_url":"https://api.github.com/users/pimterry/orgs","repos_url":"https://api.github.com/users/pimterry/repos","events_url":"https://api.github.com/users/pimterry/events{/privacy}","received_events_url":"https://api.github.com/users/pimterry/received_events","type":"User","site_admin":false},"repo":{"id":38368570,"name":"DefinitelyTyped","full_name":"pimterry/DefinitelyTyped","owner":{"login":"pimterry","id":1526883,"avatar_url":"https://avatars.githubusercontent.com/u/1526883?v=3","gravatar_id":"","url":"https://api.github.com/users/pimterry","html_url":"https://github.com/pimterry","followers_url":"https://api.github.com/users/pimterry/followers","following_url":"https://api.github.com/users/pimterry/following{/other_user}","gists_url":"https://api.github.com/users/pimterry/gists{/gist_id}","starred_url":"https://api.github.com/users/pimterry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pimterry/subscriptions","organizations_url":"https://api.github.com/users/pimterry/orgs","repos_url":"https://api.github.com/users/pimterry/repos","events_url":"https://api.github.com/users/pimterry/events{/privacy}","received_events_url":"https://api.github.com/users/pimterry/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pimterry/DefinitelyTyped","description":"The repository for high quality TypeScript type definitions.","fork":true,"url":"https://api.github.com/repos/pimterry/DefinitelyTyped","forks_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/forks","keys_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/teams","hooks_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/hooks","issue_events_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/issues/events{/number}","events_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/events","assignees_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/assignees{/user}","branches_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/branches{/branch}","tags_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/tags","blobs_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/git/refs{/sha}","trees_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/statuses/{sha}","languages_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/languages","stargazers_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/stargazers","contributors_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/contributors","subscribers_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/subscribers","subscription_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/subscription","commits_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/commits{/sha}","git_commits_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/git/commits{/sha}","comments_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/comments{/number}","issue_comment_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/issues/comments{/number}","contents_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/contents/{+path}","compare_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/merges","archive_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/downloads","issues_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/issues{/number}","pulls_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/pulls{/number}","milestones_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/milestones{/number}","notifications_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/labels{/name}","releases_url":"https://api.github.com/repos/pimterry/DefinitelyTyped/releases{/id}","created_at":"2015-07-01T11:54:42Z","updated_at":"2015-07-01T11:54:45Z","pushed_at":"2015-07-01T15:18:11Z","git_url":"git://github.com/pimterry/DefinitelyTyped.git","ssh_url":"git@github.com:pimterry/DefinitelyTyped.git","clone_url":"https://github.com/pimterry/DefinitelyTyped.git","svn_url":"https://github.com/pimterry/DefinitelyTyped","homepage":"http://definitelytyped.org/","size":61647,"stargazers_count":0,"watchers_count":0,"language":"TypeScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"borisyankov:master","ref":"master","sha":"c7b1128cc9a8f5797bade826e7632b36b06a856c","user":{"login":"borisyankov","id":867242,"avatar_url":"https://avatars.githubusercontent.com/u/867242?v=3","gravatar_id":"","url":"https://api.github.com/users/borisyankov","html_url":"https://github.com/borisyankov","followers_url":"https://api.github.com/users/borisyankov/followers","following_url":"https://api.github.com/users/borisyankov/following{/other_user}","gists_url":"https://api.github.com/users/borisyankov/gists{/gist_id}","starred_url":"https://api.github.com/users/borisyankov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/borisyankov/subscriptions","organizations_url":"https://api.github.com/users/borisyankov/orgs","repos_url":"https://api.github.com/users/borisyankov/repos","events_url":"https://api.github.com/users/borisyankov/events{/privacy}","received_events_url":"https://api.github.com/users/borisyankov/received_events","type":"User","site_admin":false},"repo":{"id":6093316,"name":"DefinitelyTyped","full_name":"borisyankov/DefinitelyTyped","owner":{"login":"borisyankov","id":867242,"avatar_url":"https://avatars.githubusercontent.com/u/867242?v=3","gravatar_id":"","url":"https://api.github.com/users/borisyankov","html_url":"https://github.com/borisyankov","followers_url":"https://api.github.com/users/borisyankov/followers","following_url":"https://api.github.com/users/borisyankov/following{/other_user}","gists_url":"https://api.github.com/users/borisyankov/gists{/gist_id}","starred_url":"https://api.github.com/users/borisyankov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/borisyankov/subscriptions","organizations_url":"https://api.github.com/users/borisyankov/orgs","repos_url":"https://api.github.com/users/borisyankov/repos","events_url":"https://api.github.com/users/borisyankov/events{/privacy}","received_events_url":"https://api.github.com/users/borisyankov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/borisyankov/DefinitelyTyped","description":"The repository for high quality TypeScript type definitions.","fork":false,"url":"https://api.github.com/repos/borisyankov/DefinitelyTyped","forks_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/forks","keys_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/keys{/key_id}","collaborators_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/teams","hooks_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/hooks","issue_events_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/issues/events{/number}","events_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/events","assignees_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/assignees{/user}","branches_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/branches{/branch}","tags_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/tags","blobs_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/git/refs{/sha}","trees_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/git/trees{/sha}","statuses_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/statuses/{sha}","languages_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/languages","stargazers_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/stargazers","contributors_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/contributors","subscribers_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/subscribers","subscription_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/subscription","commits_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/commits{/sha}","git_commits_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/git/commits{/sha}","comments_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/comments{/number}","issue_comment_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/issues/comments{/number}","contents_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/contents/{+path}","compare_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/compare/{base}...{head}","merges_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/merges","archive_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/downloads","issues_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/issues{/number}","pulls_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/pulls{/number}","milestones_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/milestones{/number}","notifications_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/labels{/name}","releases_url":"https://api.github.com/repos/borisyankov/DefinitelyTyped/releases{/id}","created_at":"2012-10-05T16:39:45Z","updated_at":"2015-07-14T15:50:23Z","pushed_at":"2015-07-14T16:44:35Z","git_url":"git://github.com/borisyankov/DefinitelyTyped.git","ssh_url":"git@github.com:borisyankov/DefinitelyTyped.git","clone_url":"https://github.com/borisyankov/DefinitelyTyped.git","svn_url":"https://github.com/borisyankov/DefinitelyTyped","homepage":"http://definitelytyped.org/","size":101113,"stargazers_count":4456,"watchers_count":4456,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2748,"mirror_url":null,"open_issues_count":653,"forks":2748,"open_issues":653,"watchers":4456,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/borisyankov/DefinitelyTyped/pulls/4791"},"html":{"href":"https://github.com/borisyankov/DefinitelyTyped/pull/4791"},"issue":{"href":"https://api.github.com/repos/borisyankov/DefinitelyTyped/issues/4791"},"comments":{"href":"https://api.github.com/repos/borisyankov/DefinitelyTyped/issues/4791/comments"},"review_comments":{"href":"https://api.github.com/repos/borisyankov/DefinitelyTyped/pulls/4791/comments"},"review_comment":{"href":"https://api.github.com/repos/borisyankov/DefinitelyTyped/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/borisyankov/DefinitelyTyped/pulls/4791/commits"},"statuses":{"href":"https://api.github.com/repos/borisyankov/DefinitelyTyped/statuses/ed15e4bd3806d00223f40803a7d13d0d3ada111e"}},"merged":true,"mergeable":null,"mergeable_state":"unknown","merged_by":{"login":"vvakame","id":125332,"avatar_url":"https://avatars.githubusercontent.com/u/125332?v=3","gravatar_id":"","url":"https://api.github.com/users/vvakame","html_url":"https://github.com/vvakame","followers_url":"https://api.github.com/users/vvakame/followers","following_url":"https://api.github.com/users/vvakame/following{/other_user}","gists_url":"https://api.github.com/users/vvakame/gists{/gist_id}","starred_url":"https://api.github.com/users/vvakame/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vvakame/subscriptions","organizations_url":"https://api.github.com/users/vvakame/orgs","repos_url":"https://api.github.com/users/vvakame/repos","events_url":"https://api.github.com/users/vvakame/events{/privacy}","received_events_url":"https://api.github.com/users/vvakame/received_events","type":"User","site_admin":false},"comments":3,"review_comments":0,"commits":3,"additions":31,"deletions":158,"changed_files":2}}