-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Labels
Milestone
Description
I find myself wanting to create a function inside a try/catch block. For example:
async function uploadImages () {
const profileUrl = buildProfileUrl()
const picturesUrl = buildPicturesUrl()
try {
const profile = await getProfile(profileUrl)
const pictures = await getPictures(picturesUrl)
async function upload (picture) {
return uploadImage({ profile, picture })
}
const promises = pictures.map(upload)
return Promise.all(promises)
} catch (error) {
throw error
}
}
I want to declare upload inside the try so I can take advantage of profile being in scope. However, this apparently violates the no-inner-declarations rule.
Can someone explain why this rule is important here? Should no-inner-declaration perhaps not apply to try/catch?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done