{"action":"created","issue":{"url":"https://api.github.com/repos/scala-js/scala-js-dom/issues/164","repository_url":"https://api.github.com/repos/scala-js/scala-js-dom","labels_url":"https://api.github.com/repos/scala-js/scala-js-dom/issues/164/labels{/name}","comments_url":"https://api.github.com/repos/scala-js/scala-js-dom/issues/164/comments","events_url":"https://api.github.com/repos/scala-js/scala-js-dom/issues/164/events","html_url":"https://github.com/scala-js/scala-js-dom/issues/164","id":114574029,"number":164,"title":"Promise.andThen signature with disjunction types","user":{"login":"bblfish","id":124506,"avatar_url":"https://avatars.githubusercontent.com/u/124506?v=3","gravatar_id":"","url":"https://api.github.com/users/bblfish","html_url":"https://github.com/bblfish","followers_url":"https://api.github.com/users/bblfish/followers","following_url":"https://api.github.com/users/bblfish/following{/other_user}","gists_url":"https://api.github.com/users/bblfish/gists{/gist_id}","starred_url":"https://api.github.com/users/bblfish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bblfish/subscriptions","organizations_url":"https://api.github.com/users/bblfish/orgs","repos_url":"https://api.github.com/users/bblfish/repos","events_url":"https://api.github.com/users/bblfish/events{/privacy}","received_events_url":"https://api.github.com/users/bblfish/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-11-02T11:11:56Z","updated_at":"2016-02-12T12:54:26Z","closed_at":null,"body":"Currently `andThen` is defined\r\n\r\n```\r\n  def andThen[B](onFulfilled: js.Function1[A,B]): Promise[Any] = js.native\r\n```\r\n\r\nThis loss of type in the response (it's of type `Promise[Any]` rather than `Promise[B]` makes it awkward  when writing functions using the `Fetch` api where one would like to write things like \r\n\r\n```\r\n def fetchListener(e: FetchEvent) = e.respondWith {\r\n       fetch(e.request.url).andThen{\r\n             response=> f(response),\r\n             err => err \r\n      }\r\n  }\r\n``` \r\nwhere respondWith takes a `Promise[Response]`. With the current signature one needs to add an extra cast.\r\n\r\nInstead the following signature seems more correct and closer to the JS documentation [I have read](http://www.html5rocks.com/en/tutorials/es6/promises/)\r\n\r\n```\r\ndef andThen[B](onFulfilled: js.Function1[A,B]|js.Function1[A,Promise[B]]): Promise[B] = js.native\r\n```\r\n\r\nHere we use the disjunction type since `andThen` can either take a function to a value or a function to something Promisy.\r\n"},"comment":{"url":"https://api.github.com/repos/scala-js/scala-js-dom/issues/comments/183313507","html_url":"https://github.com/scala-js/scala-js-dom/issues/164#issuecomment-183313507","issue_url":"https://api.github.com/repos/scala-js/scala-js-dom/issues/164","id":183313507,"user":{"login":"danielwegener","id":2953619,"avatar_url":"https://avatars.githubusercontent.com/u/2953619?v=3","gravatar_id":"","url":"https://api.github.com/users/danielwegener","html_url":"https://github.com/danielwegener","followers_url":"https://api.github.com/users/danielwegener/followers","following_url":"https://api.github.com/users/danielwegener/following{/other_user}","gists_url":"https://api.github.com/users/danielwegener/gists{/gist_id}","starred_url":"https://api.github.com/users/danielwegener/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielwegener/subscriptions","organizations_url":"https://api.github.com/users/danielwegener/orgs","repos_url":"https://api.github.com/users/danielwegener/repos","events_url":"https://api.github.com/users/danielwegener/events{/privacy}","received_events_url":"https://api.github.com/users/danielwegener/received_events","type":"User","site_admin":false},"created_at":"2016-02-12T12:54:26Z","updated_at":"2016-02-12T12:54:26Z","body":"Cool, would be willing to do that, need a short break from slide preparations :)"}}