I’d like to define a typescript interface to map answers from a web service to a type (similar to what is shown here). Here is an example answer.
{
"type": "Seen",
"creation": 33,
"fileId": 6
}
Hence the following interface would be suitable.
interface Event {
type: 'Accepted' | 'Judgment' | 'Seen';
creation: number;
fileId: number;
}
Unfortunately, the compiler does not like it: type is a reserved keyword.
How can I use a reserved keyword as a property inside an interface?
I guess it is possible to define the property using another term and then define an alias to it somehow, as suggested here, or use var instead as suggested here, but I can’t find out how to do it in my case.
It is perfectly fine to use properties called
typein aninterface. In fact, you can use all keywords of TypeScript in interfaces:The problem here is that you are modifying an existing
interfacewhich already definestypeto be of typestring:You can define multiple interfaces with the same name to merge them. This is called "Declaration Merging". But if you define the same properties with different types you get the following error:
So unless you are trying to modify the globally available interface
Event, you should just choose another name of the interface.