From 54ce8d34dfea976dddb029d0a797689249e8564e Mon Sep 17 00:00:00 2001 From: Jeremias Peier Date: Mon, 17 Jan 2022 08:47:53 +0100 Subject: [PATCH] fix(angular/core): make SbbOption generic Makes `SbbOption` generic so that consumers can type its `value` to something different from `any`. https://github.com/angular/components/pull/20242 --- src/angular/core/option/option.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/angular/core/option/option.ts b/src/angular/core/option/option.ts index ae5418503d..925d7bf3af 100644 --- a/src/angular/core/option/option.ts +++ b/src/angular/core/option/option.ts @@ -32,10 +32,10 @@ import { SbbOptionParentComponent, SBB_OPTION_PARENT_COMPONENT } from './option- let uniqueIdCounter = 0; /** Event object emitted by SbbOption when selected or deselected. */ -export class SbbOptionSelectionChange { +export class SbbOptionSelectionChange { constructor( /** Reference to the option that emitted the event. */ - public source: SbbOption, + public source: SbbOption, /** Whether the change in the option's value was a result of a user action. */ public isUserInput = false ) {} @@ -61,7 +61,9 @@ export class SbbOptionSelectionChange { '[class.sbb-disabled]': 'disabled', }, }) -export class SbbOption implements AfterViewChecked, OnDestroy, FocusableOption, Highlightable { +export class SbbOption + implements AfterViewChecked, OnDestroy, FocusableOption, Highlightable +{ private _selected = false; private _active = false; private _disabled = false; @@ -81,7 +83,7 @@ export class SbbOption implements AfterViewChecked, OnDestroy, FocusableOption, } /** The form value of the option. */ - @Input() value: any; + @Input() value: T; /** The unique ID of the option. */ @Input() id: string = `sbb-option-${uniqueIdCounter++}`; @@ -98,7 +100,7 @@ export class SbbOption implements AfterViewChecked, OnDestroy, FocusableOption, /** Event emitted when the option is selected or deselected. */ // tslint:disable-next-line:no-output-on-prefix - @Output() readonly onSelectionChange = new EventEmitter(); + @Output() readonly onSelectionChange = new EventEmitter>(); /** Emits when the state of the option changes and any parents have to be notified. */ readonly _stateChanges = new Subject(); @@ -341,7 +343,7 @@ export class SbbOption implements AfterViewChecked, OnDestroy, FocusableOption, /** Emits the selection change event. */ private _emitSelectionChangeEvent(isUserInput = false): void { - this.onSelectionChange.emit(new SbbOptionSelectionChange(this, isUserInput)); + this.onSelectionChange.emit(new SbbOptionSelectionChange(this, isUserInput)); } static ngAcceptInputType_disabled: BooleanInput;