I am working on developing an interface for a JSON object that consists of n keys with unknown names, each containing an array of functions with specific signatures.
// CLASSES
class Server {
// Private variables
mapping : IMapping = {}
// Public functions
public use(endPoint = "", handler : IHandler) : void {
// Check if the end point exists in the mapping
if(this.mapping[endPoint] === undefined) {
this.mapping[endPoint] = {
[endPoint] : [handler]
};
} else {
}
}
}
// INTERFACES
interface IMapping
{
[key : string] : IHandler[];
}
interface IHandler {
(req : object, res : object, next : object) : void;
}
The issue arises when evaluating: this.mapping[endPoint]
, resulting in
Type '{ [x: string]: IHandler[]; }' is not assignable to type 'IHandler[]'.
Property 'length' is missing in type '{ [x: string]: IHandler[]; }'.