I've been developing a front-end Angular application that interacts with the Wordpress REST API to fetch and display post data. My goal is to create an interface to handle the responses and render the posts in the template.
However, I encountered an issue when creating the interface file. The JSON response structure from the server is as follows:
[
{
"id": 1,
"date": "2021-08-04T22:24:09",
"date_gmt": "2021-08-04T19:24:09",
"guid": {
"rendered": "http://localhost/wordpress/?p=1"
},
...
}
]
Here's a snippet of the interface I have created so far:
export interface Question {
id: number;
date: string;
date_gmt: string;
guid: {
rendered: string
};
...
}
When trying to compile the interface file, I encountered the error message:
The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
This error seems to be related to the properties version-history
, wp:attachment
, and wp:term
. Renaming these properties, for example to version_history
or versionhistory
, resolves the error. It appears that TypeScript has trouble recognizing the characters -
and :
in property names within interfaces. Why is this?