fix(forms): type NG_VALUE_ACCESSOR injection token as array (#29723)

NG_VALUE_ACCESSOR is a multi injection token, users can and
should expect more than one ControlValueAccessor to be
available (and this is how it is used in @angular/forms).

This is now reflected in the definition of the injection token
by typing it as an array of ControlValueAccessor. The motivating
reason is that using the programmatic Injector api will now
type Injector#get correspondingly.

fixes #29351

BREAKING CHANGES

NG_VALUE_ACCESSOR is now typed as a readonly array rather than
a mutable scalar. It is used as a multi injection token and as
such it should always be expected that more than one accessor
may be returned.

PR Close #29723
This commit is contained in:
Ingo Bürk 2020-05-08 09:06:35 +02:00 committed by Misko Hevery
parent fdd4fa0009
commit 2b1b7180db
2 changed files with 3 additions and 2 deletions

View File

@ -349,7 +349,7 @@ export declare const NG_ASYNC_VALIDATORS: InjectionToken<(Function | Validator)[
export declare const NG_VALIDATORS: InjectionToken<(Function | Validator)[]>;
export declare const NG_VALUE_ACCESSOR: InjectionToken<ControlValueAccessor>;
export declare const NG_VALUE_ACCESSOR: InjectionToken<readonly ControlValueAccessor[]>;
export declare abstract class NgControl extends AbstractControlDirective {
get asyncValidator(): AsyncValidatorFn | null;

View File

@ -138,4 +138,5 @@ export interface ControlValueAccessor {
*
* @publicApi
*/
export const NG_VALUE_ACCESSOR = new InjectionToken<ControlValueAccessor>('NgValueAccessor');
export const NG_VALUE_ACCESSOR =
new InjectionToken<ReadonlyArray<ControlValueAccessor>>('NgValueAccessor');