{"action":"created","issue":{"url":"https://api.github.com/repos/prettier/prettier/issues/4710","repository_url":"https://api.github.com/repos/prettier/prettier","labels_url":"https://api.github.com/repos/prettier/prettier/issues/4710/labels{/name}","comments_url":"https://api.github.com/repos/prettier/prettier/issues/4710/comments","events_url":"https://api.github.com/repos/prettier/prettier/issues/4710/events","html_url":"https://github.com/prettier/prettier/issues/4710","id":333074593,"node_id":"MDU6SXNzdWUzMzMwNzQ1OTM=","number":4710,"title":"Prettier Strips Parens from JSDoc Type Cast","user":{"login":"rbiggs","id":249218,"node_id":"MDQ6VXNlcjI0OTIxOA==","avatar_url":"https://avatars0.githubusercontent.com/u/249218?v=4","gravatar_id":"","url":"https://api.github.com/users/rbiggs","html_url":"https://github.com/rbiggs","followers_url":"https://api.github.com/users/rbiggs/followers","following_url":"https://api.github.com/users/rbiggs/following{/other_user}","gists_url":"https://api.github.com/users/rbiggs/gists{/gist_id}","starred_url":"https://api.github.com/users/rbiggs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbiggs/subscriptions","organizations_url":"https://api.github.com/users/rbiggs/orgs","repos_url":"https://api.github.com/users/rbiggs/repos","events_url":"https://api.github.com/users/rbiggs/events{/privacy}","received_events_url":"https://api.github.com/users/rbiggs/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-06-17T16:23:04Z","updated_at":"2018-06-17T16:47:42Z","closed_at":"2018-06-17T16:47:35Z","author_association":"NONE","body":"**Prettier 1.13.5**\r\n[Playground link](https://prettier.io/playground/#N4Igxg9gdgLgprEAuEB6AVOgBAARgTwAc4tgAJAFQFkAZAUQBs4BbBGAXy3VSwAo4mrWAEoAdACcWEAG5wAgjBjiAlgCMArvF6FxEQsJAAaEHpjLoAZ2SgAhuN0B3AAp2EVlDekRlAEyMhVcRswAGs4GABlQmDlKABzZCV1OGNYizhxGCcguOYbZAAzGwZ04wArCwAPACEg0PCIm1YaWLhC4tKQaPF08WQAm1V8Bmh-HViYAHVfGAALZAAOAAZjHQh0yaDCfp04Xtl-SQBHdWVJbJtc-KQikpSQdOZlRPFk4wtYuKYARXUIeHad2MMEG0x8c2QACZgUFlAxPgBhCDMPL9KDQNrGdTpCiDdy3dLsdhAA)\r\n```sh\r\n--parser babylon\r\n```\r\n\r\n**Input:**\r\n```jsx\r\n/** @type {HTMLElement} */ (element).removeAttribute(prop)\r\n```\r\n\r\n**Output:**\r\n```jsx\r\n/** @type {HTMLElement} */ element.removeAttribute(prop);\r\n\r\n```\r\n\r\n**Expected behavior:**\r\n\r\n```jsx\r\n/** @type {HTMLElement} */ (element).removeAttribute(prop)\r\n```\r\n\r\nJSDoc supports type casting by using an inline comment with the type and by enclosing the target element in parens. Prettier is stripping those parens out, causing the type cast to fail. In the above JavaScript, `element` is of type `Node`, which only has prositional properties and methods. To use `setAttribute`, `removeAttribute` and other Element features, you need to type cast the element to type HTMLElement. This is done with the inline comment and by enclosing the object to cast in parens. Removing those parens causes the type checker to flag the element as an error since `removeAttribute` does not exist on type Node. \r\n\r\nYou can read more about JSDoc type casting here (scroll down to the bottom of the page): https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler\r\nOr here in the Visual Studio Code documentation: https://github.com/Microsoft/TypeScript/wiki/JSDoc-support-in-JavaScript. Scroll down to the last item in the supported features, right before `Patterns that are known NOT to be supported`"},"comment":{"url":"https://api.github.com/repos/prettier/prettier/issues/comments/397891284","html_url":"https://github.com/prettier/prettier/issues/4710#issuecomment-397891284","issue_url":"https://api.github.com/repos/prettier/prettier/issues/4710","id":397891284,"node_id":"MDEyOklzc3VlQ29tbWVudDM5Nzg5MTI4NA==","user":{"login":"ikatyang","id":8341033,"node_id":"MDQ6VXNlcjgzNDEwMzM=","avatar_url":"https://avatars1.githubusercontent.com/u/8341033?v=4","gravatar_id":"","url":"https://api.github.com/users/ikatyang","html_url":"https://github.com/ikatyang","followers_url":"https://api.github.com/users/ikatyang/followers","following_url":"https://api.github.com/users/ikatyang/following{/other_user}","gists_url":"https://api.github.com/users/ikatyang/gists{/gist_id}","starred_url":"https://api.github.com/users/ikatyang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ikatyang/subscriptions","organizations_url":"https://api.github.com/users/ikatyang/orgs","repos_url":"https://api.github.com/users/ikatyang/repos","events_url":"https://api.github.com/users/ikatyang/events{/privacy}","received_events_url":"https://api.github.com/users/ikatyang/received_events","type":"User","site_admin":false},"created_at":"2018-06-17T16:47:42Z","updated_at":"2018-06-17T16:47:42Z","author_association":"COLLABORATOR","body":"Duplicate of #4287"}}
{"actor":{"display_login":"ikatyang"}}