1

I was looking at the angular 2 validator file . Can someone explain the syntax after "new InjectionToken"? I know its a generic type but how do you understand it?

new InjectionToken<Array<Validator|Function>>('NgValidators');
Jdsans
  • 194
  • 2
  • 17

1 Answers1

3

Your token can take the following type

Array<Validator|Function>

it means array of Validator or Function

where Validator is a class that implements Validator interface:

export interface Validator {
  validate(c: AbstractControl): ValidationErrors|null;
  registerOnValidatorChange?(fn: () => void): void;
}

InjectionToken gives you type checking benefit when getting a dependency through injector instance

See also

yurzui
  • 205,937
  • 32
  • 433
  • 399