Skip to content

Commit

Permalink
Set strictNullChecks to true and fix all errors (#475)
Browse files Browse the repository at this point in the history
Co-authored-by: Esteban Gehring <esteban.gehring@bithost.ch>
  • Loading branch information
davidsansome and macjohnny authored Aug 23, 2024
1 parent 216fa59 commit 83db8e3
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export class SingleSelectionExampleComponent implements OnInit, AfterViewInit, O
protected banks: Bank[] = BANKS;

/** control for the selected bank */
public bankCtrl: FormControl<Bank> = new FormControl<Bank>(null);
public bankCtrl: FormControl<Bank | null> = new FormControl<Bank | null>(null);

/** control for the MatSelect filter keyword */
public bankFilterCtrl: FormControl<string> = new FormControl<string>('');
public bankFilterCtrl: FormControl<string> = new FormControl<string>('', {nonNullable: true});

/** list of banks filtered by search keyword */
public filteredBanks: ReplaySubject<Bank[]> = new ReplaySubject<Bank[]>(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export class MultipleSelectionExampleComponent implements OnInit, AfterViewInit,
protected banks: Bank[] = BANKS;

/** control for the selected bank for multi-selection */
public bankMultiCtrl: FormControl<Bank[]> = new FormControl<Bank[]>([]);
public bankMultiCtrl: FormControl<Bank[]> = new FormControl<Bank[]>([], {nonNullable: true});

/** control for the MatSelect filter keyword multi-selection */
public bankMultiFilterCtrl: FormControl<string> = new FormControl<string>('');
public bankMultiFilterCtrl: FormControl<string> = new FormControl<string>('', {nonNullable: true});

/** list of banks filtered by search keyword */
public filteredBanksMulti: ReplaySubject<Bank[]> = new ReplaySubject<Bank[]>(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export class OptionGroupsExampleComponent implements OnInit, OnDestroy {
protected bankGroups: BankGroup[] = BANKGROUPS;

/** control for the selected bank for option groups */
public bankGroupsCtrl: FormControl<Bank> = new FormControl<Bank>(null);
public bankGroupsCtrl: FormControl<Bank | null> = new FormControl<Bank | null>(null);

/** control for the MatSelect filter keyword for option groups */
public bankGroupsFilterCtrl: FormControl<string> = new FormControl<string>('');
public bankGroupsFilterCtrl: FormControl<string> = new FormControl<string>('', {nonNullable: true});

/** list of bank groups filtered by search keyword for option groups */
public filteredBankGroups: ReplaySubject<BankGroup[]> = new ReplaySubject<BankGroup[]>(1);
Expand Down Expand Up @@ -75,7 +75,7 @@ export class OptionGroupsExampleComponent implements OnInit, OnDestroy {
}

protected copyBankGroups(bankGroups: BankGroup[]) {
const bankGroupsCopy = [];
const bankGroupsCopy: BankGroup[] = [];
bankGroups.forEach(bankGroup => {
bankGroupsCopy.push({
name: bankGroup.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export class ServerSideSearchExampleComponent implements OnInit, OnDestroy {
protected banks: Bank[] = BANKS;

/** control for the selected bank for server side filtering */
public bankServerSideCtrl: FormControl<Bank> = new FormControl<Bank>(null);
public bankServerSideCtrl: FormControl<Bank | null> = new FormControl<Bank | null>(null);

/** control for filter for server side. */
public bankServerSideFilteringCtrl: FormControl<string> = new FormControl<string>('');
public bankServerSideFilteringCtrl: FormControl<string> = new FormControl<string>('', {nonNullable: true});

/** indicate search operation is in progress */
public searching = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export class MultipleSelectionSelectAllExampleComponent implements OnInit, After
protected banks: Bank[] = BANKS;

/** control for the selected bank for multi-selection */
public bankMultiCtrl: FormControl<Bank[]> = new FormControl<Bank[]>([]);
public bankMultiCtrl: FormControl<Bank[]> = new FormControl<Bank[]>([], {nonNullable: true});

/** control for the MatSelect filter keyword multi-selection */
public bankMultiFilterCtrl: FormControl<string> = new FormControl<string>('');
public bankMultiFilterCtrl: FormControl<string> = new FormControl<string>('', {nonNullable: true});

/** list of banks filtered by search keyword */
public filteredBanksMulti: ReplaySubject<Bank[]> = new ReplaySubject<Bank[]>(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export class TooltipSelectAllExampleComponent implements OnInit, AfterViewInit,
protected banks: Bank[] = BANKS;

/** control for the selected bank for multi-selection */
public bankMultiCtrl: FormControl<Bank[]> = new FormControl<Bank[]>([]);
public bankMultiCtrl: FormControl<Bank[]> = new FormControl<Bank[]>([], {nonNullable: true});

/** control for the MatSelect filter keyword multi-selection */
public bankMultiFilterCtrl: FormControl<string> = new FormControl<string>('');
public bankMultiFilterCtrl: FormControl<string> = new FormControl<string>('', {nonNullable: true});

/** list of banks filtered by search keyword */
public filteredBanksMulti: ReplaySubject<Bank[]> = new ReplaySubject<Bank[]>(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export class InfiniteScrollExampleComponent implements OnInit, OnDestroy {
}));

/** control for the selected bank id */
public bankCtrl: FormControl<string> = new FormControl<string>(null);
public bankCtrl: FormControl<string | null> = new FormControl<string | null>(null);

/** control for the MatSelect filter keyword */
public bankFilterCtrl: FormControl<string> = new FormControl<string>('');
public bankFilterCtrl: FormControl<string> = new FormControl<string>('', {nonNullable: true});

/** list of data corresponding to the search input */
private filteredData$: Observable<Bank[]> = this.bankFilterCtrl.valueChanges.pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export class CustomNoEntriesFoundExampleComponent implements OnInit, AfterViewIn
protected banks: Bank[] = BANKS;

/** control for the selected bank */
public bankCtrl: FormControl<Bank> = new FormControl<Bank>(null);
public bankCtrl: FormControl<Bank | null> = new FormControl<Bank | null>(null);

/** control for the MatSelect filter keyword */
public bankFilterCtrl: FormControl<string> = new FormControl<string>('');
public bankFilterCtrl: FormControl<string> = new FormControl<string>('', {nonNullable: true});

/** list of banks filtered by search keyword */
public filteredBanks: ReplaySubject<Bank[]> = new ReplaySubject<Bank[]>(1);
Expand Down
4 changes: 2 additions & 2 deletions src/app/mat-select-search/mat-select-search.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ export class MatSelectSearchTestComponent implements OnInit, OnDestroy, AfterVie
/** list of banks filtered by search keyword for multi-selection */
public filteredBanksMulti: ReplaySubject<Bank[]> = new ReplaySubject<Bank[]>(1);

public initialSingleSelection: Bank = null;
public initialSingleSelectionMatOption: Bank = null;
public initialSingleSelection: Bank;
public initialSingleSelectionMatOption: Bank;
public initialMultiSelection: Bank[] = [];


Expand Down
31 changes: 18 additions & 13 deletions src/app/mat-select-search/mat-select-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class MatSelectSearchComponent implements OnInit, OnDestroy, ControlValue
get value(): string {
return this._formControl.value;
}
private _lastExternalInputValue: string;
private _lastExternalInputValue?: string;

onTouched: Function = (_: any) => { };

Expand All @@ -224,9 +224,9 @@ export class MatSelectSearchComponent implements OnInit, OnDestroy, ControlValue
public get _options(): QueryList<MatOption> {
return this._options$.getValue();
}
public _options$: BehaviorSubject<QueryList<MatOption>> = new BehaviorSubject<QueryList<MatOption>>(null);
public _options$: BehaviorSubject<QueryList<MatOption>> = new BehaviorSubject<QueryList<MatOption>>(null as any);

private optionsList$: Observable<MatOption[]> = this._options$.pipe(
private optionsList$: Observable<MatOption[] | null> = this._options$.pipe(
switchMap(_options => _options ?
_options.changes.pipe(
map(options => options.toArray()),
Expand All @@ -242,15 +242,15 @@ export class MatSelectSearchComponent implements OnInit, OnDestroy, ControlValue
/** Previously selected values when using <mat-select [multiple]="true">*/
private previousSelectedValues: any[];

public _formControl: FormControl<string> = new FormControl<string>('');
public _formControl: FormControl<string> = new FormControl<string>('', {nonNullable: true});

/** whether to show the no entries found message */
public _showNoEntriesFound$: Observable<boolean> = combineLatest([
this._formControl.valueChanges,
this.optionsLength$
]).pipe(
map(([value, optionsLength]) => this.noEntriesFoundLabel && value
&& optionsLength === this.getOptionsLengthOffset())
map(([value, optionsLength]) => !!(this.noEntriesFoundLabel && value
&& optionsLength === this.getOptionsLengthOffset()))
);

/** Subject that emits when the component has been destroyed. */
Expand All @@ -262,14 +262,14 @@ export class MatSelectSearchComponent implements OnInit, OnDestroy, ControlValue
constructor(@Inject(MatSelect) public matSelect: MatSelect,
public changeDetectorRef: ChangeDetectorRef,
private _viewportRuler: ViewportRuler,
@Optional() @Inject(MatOption) public matOption: MatOption = null,
@Optional() @Inject(MatFormField) public matFormField: MatFormField = null,
@Optional() @Inject(MatOption) public matOption: MatOption,
@Optional() @Inject(MatFormField) public matFormField: MatFormField,
@Optional() @Inject(MAT_SELECTSEARCH_DEFAULT_OPTIONS) defaultOptions?: MatSelectSearchOptions
) {
this.applyDefaultOptions(defaultOptions);
}

private applyDefaultOptions(defaultOptions: MatSelectSearchOptions) {
private applyDefaultOptions(defaultOptions?: MatSelectSearchOptions) {
if (!defaultOptions) {
return;
}
Expand Down Expand Up @@ -355,7 +355,7 @@ export class MatSelectSearchComponent implements OnInit, OnDestroy, ControlValue
// Indiciates we should set it as active and scroll to the top.
if (firstOptionIsChanged
|| !keyManager.activeItem
|| !options.find(option => this.matSelect.compareWith(option.value, keyManager.activeItem.value))) {
|| !options.find(option => this.matSelect.compareWith(option.value, keyManager.activeItem?.value))) {
keyManager.setActiveItem(this.getOptionsLengthOffset());
}

Expand Down Expand Up @@ -537,6 +537,10 @@ export class MatSelectSearchComponent implements OnInit, OnDestroy, ControlValue
// because the option is not available while we are currently filtering
this.previousSelectedValues = this.matSelect.ngControl.value;

if (!this.matSelect.ngControl.valueChanges) {
return;
}

this.matSelect.ngControl.valueChanges
.pipe(takeUntil(this._onDestroy))
.subscribe((values) => {
Expand Down Expand Up @@ -575,9 +579,10 @@ export class MatSelectSearchComponent implements OnInit, OnDestroy, ControlValue
if (!this.innerSelectSearch || !this.innerSelectSearch.nativeElement) {
return;
}
let element: HTMLElement = this.innerSelectSearch.nativeElement;
let panelElement: HTMLElement;
while (element = element.parentElement) {
let element: HTMLElement | null = this.innerSelectSearch.nativeElement;
let panelElement: HTMLElement | null = null;
while (element && element.parentElement) {
element = element.parentElement;
if (element.classList.contains('mat-select-panel')) {
panelElement = element;
break;
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"declaration": false,
"moduleResolution": "node",
"experimentalDecorators": true,
"strictNullChecks": true,
"target": "ES2022",
"typeRoots": [
"node_modules/@types"
Expand Down

0 comments on commit 83db8e3

Please sign in to comment.