Repository navigation
Fix JavaScript arrow function SyntaxError in REST API examples - #47075
Conversation
|
Thanks for opening this pull request! A GitHub docs team member should be by to give feedback soon. In the meantime, please check out the contributing guidelines. |
How to review these changes 👓Thank you for your contribution. To review these changes, choose one of the following options: A Hubber will need to deploy your changes internally to review. Table of review linksNote: Please update the URL for your staging server or codespace. The table shows the files in the
Key: fpt: Free, Pro, Team; ghec: GitHub Enterprise Cloud; ghes: GitHub Enterprise Server 🤖 This comment is automatically generated. |
There was a problem hiding this comment.
🟡 Changes recommended
An active documentation issue remains because an unnecessary HTML directive is rendered inside fenced shell examples and may be copied as part of the API response, appearing in two locations.
1 open issue
What changed in this PR
This pull request fixes invalid JavaScript arrow-function syntax in REST API documentation examples so mapped object literals are returned correctly.
Changes:
- Wraps the returned object literals in parentheses in both JavaScript examples.
- Adds Markdown lint suppressions to two HTTP response examples.
| File | Description |
|---|---|
| content/rest/using-the-rest-api/getting-started-with-the-rest-api.md | Fixes the JavaScript mapping example and adds lint suppressions to two HTTP response examples. |
| content/rest/quickstart.md | Fixes the JavaScript mapping example to use valid arrow-function syntax. |
Review effort: Lite
ecc89d6 to
b72e0c0
Compare
subatoi
left a comment
There was a problem hiding this comment.
Thanks for spotting that and raising a fix, @ShakilUrRehman21. I'll get this merged now
|
Thanks very much for contributing! Your pull request has been merged 🎉 You should see your changes appear on the site in approximately 24 hours. If you're looking for your next contribution, check out our help wanted issues ⚡ |

Why:
Closes: N/A
In
content/rest/quickstart.mdandcontent/rest/using-the-rest-api/getting-started-with-the-rest-api.md, the example JavaScript snippet for mapping through API results contains an invalid arrow function expression:const titleAndAuthor = result.data.map(issue => {title: issue.title, authorID: issue.user.id})Because
{ ... }in an arrow function body is parsed by JavaScript as a block statement with a label (title:) rather than an object literal, running this code in Node.js throws a fatal error:SyntaxError: Unexpected token ':'
Wrapping the returned object literal in parentheses (
({ ... })) resolves the syntax error so users running the tutorial code can execute it without failure.What's being changed (if available, include any code snippets, screenshots, or gifs):
Updated the arrow function to
issue => ({ title: issue.title, authorID: issue.user.id })in:content/rest/quickstart.mdcontent/rest/using-the-rest-api/getting-started-with-the-rest-api.mdBefore:
const titleAndAuthor = result.data.map(issue => {title: issue.title, authorID: issue.user.id})After:
const titleAndAuthor = result.data.map(issue => ({ title: issue.title, authorID: issue.user.id }))Check off the following: