{"action":"opened","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/24021","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/24021/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/24021/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/24021/events","html_url":"https://github.com/Microsoft/TypeScript/issues/24021","id":321896235,"number":24021,"title":"Arrow function with comment and type assertion will be compiled into unexpected ES5 script","user":{"login":"jet2jet","id":34238471,"avatar_url":"https://avatars0.githubusercontent.com/u/34238471?v=4","gravatar_id":"","url":"https://api.github.com/users/jet2jet","html_url":"https://github.com/jet2jet","followers_url":"https://api.github.com/users/jet2jet/followers","following_url":"https://api.github.com/users/jet2jet/following{/other_user}","gists_url":"https://api.github.com/users/jet2jet/gists{/gist_id}","starred_url":"https://api.github.com/users/jet2jet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jet2jet/subscriptions","organizations_url":"https://api.github.com/users/jet2jet/orgs","repos_url":"https://api.github.com/users/jet2jet/repos","events_url":"https://api.github.com/users/jet2jet/events{/privacy}","received_events_url":"https://api.github.com/users/jet2jet/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-10T11:15:09Z","updated_at":"2018-05-10T11:15:09Z","closed_at":null,"author_association":"NONE","body":"**TypeScript Version:** 2.8.1, 2.9.0-dev.20180510\r\n\r\n**Search Terms:** \r\n\r\n* arrow\r\n* return undefined\r\n\r\n**Code**\r\n\r\n```ts\r\nconst pickupNumbers = (a: any[]) => (\r\n    // filter by numbers\r\n    a.filter((x) => (typeof x === 'number')) as number[]\r\n);\r\nconsole.log(pickupNumbers([0, 1, 2, '3', '4', 5, null]));\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nArray `[0, 1, 2, 5]` will be logged\r\n\r\n**Actual behavior:**\r\n\r\n`undefined` will be logged\r\n\r\n**Playground Link:** <!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior --> \r\n\r\nhttps://www.typescriptlang.org/play/index.html#src=const%20pickupNumbers%20%3D%20(a%3A%20any%5B%5D)%20%3D%3E%20(%0D%0A%20%20%20%20%2F%2F%20filter%20by%20numbers%0D%0A%20%20%20%20a.filter((x)%20%3D%3E%20(typeof%20x%20%3D%3D%3D%20'number'))%20as%20number%5B%5D%0D%0A)%3B%0D%0Aconsole.log(pickupNumbers(%5B0%2C%201%2C%202%2C%20'3'%2C%20'4'%2C%205%2C%20null%5D))%3B%0D%0A\r\n\r\n**Details:**\r\n\r\nThe above TS code will be compiled to the following (target: es5):\r\n\r\n```js\r\nvar pickupNumbers = function (a) { return \r\n// filter by numbers\r\na.filter(function (x) { return (typeof x === 'number'); }); };\r\nconsole.log(pickupNumbers([0, 1, 2, '3', '4', 5, null]));\r\n```\r\n\r\n`return` in the first line is treated as returning nothing, so `undefined` will be returned. The parentheses around `a.filter(...)` are dropped when both comment and type assertion are written inside the parentheses.\r\n\r\n**Workaround:**\r\n\r\n1. Remove comment before compiling\r\n2. Remove type assertion, or move `as number[]` after the parentheses (or put `<number[]>` before the parentheses)\r\n3. Use block statement instead of expression"}}
{"actor":{"display_login":"jet2jet"}}