Skip to content

Commit

Permalink
fix(forms): type NG_VALUE_ACCESSOR injection token as array
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Airblader committed Sep 10, 2020
1 parent ba95b79 commit a2f7c57
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion goldens/public-api/forms/forms.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion packages/forms/src/directives/control_value_accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,5 @@ export interface ControlValueAccessor {
*
* @publicApi
*/
export const NG_VALUE_ACCESSOR = new InjectionToken<ControlValueAccessor>('NgValueAccessor');
export const NG_VALUE_ACCESSOR =
new InjectionToken<readonly ControlValueAccessor[]>('NgValueAccessor');

0 comments on commit a2f7c57

Please sign in to comment.