From 2b1b7180db3e80d8717eb4a39ed38570aa4970ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20B=C3=BCrk?= Date: Fri, 8 May 2020 09:06:35 +0200 Subject: [PATCH] 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 --- goldens/public-api/forms/forms.d.ts | 2 +- packages/forms/src/directives/control_value_accessor.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/goldens/public-api/forms/forms.d.ts b/goldens/public-api/forms/forms.d.ts index 5733623c01..a2926bb425 100644 --- a/goldens/public-api/forms/forms.d.ts +++ b/goldens/public-api/forms/forms.d.ts @@ -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; +export declare const NG_VALUE_ACCESSOR: InjectionToken; export declare abstract class NgControl extends AbstractControlDirective { get asyncValidator(): AsyncValidatorFn | null; diff --git a/packages/forms/src/directives/control_value_accessor.ts b/packages/forms/src/directives/control_value_accessor.ts index 808ebe7c9a..5e169ca39e 100644 --- a/packages/forms/src/directives/control_value_accessor.ts +++ b/packages/forms/src/directives/control_value_accessor.ts @@ -138,4 +138,5 @@ export interface ControlValueAccessor { * * @publicApi */ -export const NG_VALUE_ACCESSOR = new InjectionToken('NgValueAccessor'); +export const NG_VALUE_ACCESSOR = + new InjectionToken>('NgValueAccessor');