interface StringValidator { isAcceptable(s: string): boolean; }
let validators: { [s: string]: StringValidator } = {};
My understanding of typescript is limited and I tried looking at the docs but I couldn't quite navigate to the correct location to answer this question.
My understanding of the code is:
first: we have an interface, self-explanatory, an object of type StringValidator must have an isAcceptable method, which takes a single string-type argument, and returns a boolean value
second: we have a variable named 'validators', which is wholly undecipherable to me
Questions:
why is the array element in the validators object { [s: string]: StringValidator } not a variable name? my understanding is that any object member is a variable in itself, and the name must be supplied, all I see is a cryptic array declaration
why is the obviously apparent array of type string assigned another type? is that to say that the elements (which should be of type string) implementing the stringvalidator interface? what the heck even is that?
Can somebody (anybody) explain (any links are highly appreciated) what the heck is going on with this statement 'let validators: { [s: string]: StringValidator } = {};'
I have no clue how to interpret this, any and all suggestions/help is highly appreciated
validatorstype is an object with string keys andStringValidatorvalues. Think of it likeRecord<string, StringValidator>