The following eslint errors are generated by the code below :
@typescript-eslint/no-unsafe-member-access: Unsafe member access ['content-type'] on an any value.
export const getGraphPhoto = async () => {
try {
const response = await getGraphDetails(
config.resources.msGraphPhoto.uri,
config.resources.msGraphPhoto.scopes,
{ responseType: 'arraybuffer' }
)
if (!(response && response.data)) {
return ''
}
const imageBase64 = new Buffer(response.data, 'binary').toString('base64')
return `data:${response.headers['content-type']};base64, ${imageBase64}`
} catch (error) {
throw new Error(`Failed retrieving the graph photo: ${error as string}`)
}
}
The promise getGraphDetails
returns Promise<AxiosResponse<any>>
The issue is clearly that the property response.headers['content-type']
might not be present on the response
object. To fix this I tried checking for it first but that doesn't get rid of the warning:
if (
!(response && response.data && response.headers && response.headers['content-type'])
) { return '' }
Thank you for any guidance you can give me to better understand and solve this issue.