I have the following interface:
interface SMJSPacket {
header: {
tag: string;
method: string;
type: string;
};
response?: {
status: string;
content: string;
};
event?: {
key?: string;
action?: string;
};
request?: {
run?: string;
};
}
And then I want to implement it as a class and the properties being set in the constructor:
class Request implements SMJSPacket {
constructor(data: any, method: string) {
this.header = {
type: 'request',
method: method || 'calld',
tag: Request.getTag()
}
this.request = data;
}
static getTag(): string {
return '_' + goog.now() + '_' + utils.getRandomBetween(1, 1000);
}
}
However according to the compiler Request is not implementing the interface. I don't understand how does it check it, whilst it has everything filled according to the interface at the construction phase and if written in JavaScript this would work fine, type checking the same thing in Closure tools also works perfectly. The idea is that I want to implement the interface as a class so I can have utility methods in the prototype but still be able to easily convert to JSON string.
Any ideas?
Thanks