For:
resource access refers to the type of this index signature
Access to properties in this case is a bracket:
interface MapStringToFunction { [index: string]: Function; } var dict: MapStringToFunction = {}; dict['say'] = () => 'hi'; dict['say']();
More details
Below will be a compile time error:
interface MapStringToFunction { [index: string]: Function; say: number;
In our case, a function is the only type of property that allows you to:
interface MapStringToFunction { [index: string]: Function; say: Function; }
However, in order to be able to use any property, it must be declared
Otherwise, it will open too much insecure type access. For example , if what you offer is allowed, the following will only work at run time and not compile time :
interface MapStringToFunction { [index: string]: Function; } var dict: MapStringToFunction = {}; dict.say()
source share