Could someone please clarify the TypeScript syntax shown below for me?
{[s: string]: boolean}
This is the return type for a ValidatorFn
in Angular 2. What exactly does the array: [s: string]
represent?
When creating my own custom ValidatorFn
function, what is the significance of the boolean value? I noticed that there doesn't seem to be a difference between the two examples below:
startsWithZero(control: FormControl): {[s: string]: boolean} {
if (control.value.indexOf('0') !== 0) {
return {'does not start with zero': true};
}
return null;
}
vs.
startsWithZero(control: FormControl): {[s: string]: boolean} {
if (control.value.indexOf('0') !== 0) {
return {'does not start with zero': false};
}
return null;
}
The explanation in the Angular documentation is somewhat vague on this topic, and I couldn't find much information on Google. Thank you in advance!