In my SPFX web part, the web service I am calling has properties that start with numbers: 30DaysTotal, 60DaysTotal, and 90DaysTotal.
To handle this, I have defined an Interface as follows:
export interface ISummary {
Id : number;
"30DaysGrandTotal": number;
"60DaysGrandTotal": number;
"90DaysGrandTotal": number;
}
Upon conducting some research, I discovered that adding speech marks around the variables makes them acceptable.
I then used the standard method out of the box to retrieve the values:
this.context.aadHttpClientFactory
.getClient('('*********************',')
.then((client: AadHttpClient): void => {
client
.get('*********************', AadHttpClient.configurations.v1)
.then((response: HttpClientResponse): Promise<ISummary> => {
return response.json();
})
.then((summary: ISummary): void => {
console.log(summary);
let summaryList: string='';
summaryList = `
<li>${summary.Id}</li>
<li>${summary.30DaysGrandTotal}</li>
<li>${summary.60DaysGrandTotal}</li>
<li>${summary.90DaysGrandTotal}</li>
`;
this.summaryDetailsElement.innerHTML = `
<div name="summary" id="summary"><ul>${summaryList}</ul></div>`;
});
});
However, I encountered errors when trying to build the solution due to the variables:
[16:42:03] Error - [tsc] src/webparts/aadHttpClient/AadHttpClientWebPart.ts(189,28): error TS1005: '}' expected.
[16:42:03] Error - [tsc] src/webparts/aadHttpClient/AadHttpClientWebPart.ts(189,31): error TS1005: ';' expected.
[16:42:03] Error - [tsc] src/webparts/aadHttpClient/AadHttpClientWebPart.ts(189,46): error TS1005: ',' expected.
[16:42:03] Error - [tsc] src/webparts/aadHttpClient/AadHttpClientWebPart.ts(189,47): error TS1110: Type expected.
[16:42:03] Error - [tsc] src/webparts/aadHttpClient/AadHttpClientWebPart.ts(189,48): error TS1161: Unterminated regular expression literal.
If I remove the three lines containing these variables, the code builds successfully, and the summary Class with values is logged in the console.
My query now is what modifications are needed for the variables to allow the code to be built without errors?