Skip to content

feat: support strictNullChecks #3486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"outDir": "../dist/e2e/",
"rootDir": ".",
"sourceMap": true,
"strictNullChecks": true,
"target": "es5",
"typeRoots": [
"../node_modules/@types"
Expand Down
1 change: 1 addition & 0 deletions src/demo-app/tsconfig-aot.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": true,
"strictNullChecks": true,
"target": "es5",
"baseUrl": "",
"typeRoots": [
Expand Down
1 change: 1 addition & 0 deletions src/demo-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"sourceMap": true,
"target": "es5",
"stripInternal": false,
"strictNullChecks": true,
"baseUrl": "",
"typeRoots": [
"../../node_modules/@types/!(node)"
Expand Down
1 change: 1 addition & 0 deletions src/e2e-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"sourceMap": true,
"target": "es5",
"stripInternal": false,
"strictNullChecks": true,
"baseUrl": "",
"typeRoots": [
"../../node_modules/@types/!(node)"
Expand Down
6 changes: 3 additions & 3 deletions src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const MD_AUTOCOMPLETE_VALUE_ACCESSOR: any = {
providers: [MD_AUTOCOMPLETE_VALUE_ACCESSOR]
})
export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
private _overlayRef: OverlayRef;
private _overlayRef: OverlayRef|null;
private _portal: TemplatePortal;
private _panelOpen: boolean = false;

Expand Down Expand Up @@ -123,7 +123,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
this._createOverlay();
}

if (!this._overlayRef.hasAttached()) {
if (this._overlayRef && !this._overlayRef.hasAttached()) {
this._overlayRef.attach(this._portal);
this._subscribeToClosingActions();
}
Expand Down Expand Up @@ -160,7 +160,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
}

/** The currently active option, coerced to MdOption type. */
get activeOption(): MdOption {
get activeOption(): MdOption|undefined {
if (this.autocomplete._keyManager) {
return this.autocomplete._keyManager.activeItem as MdOption;
}
Expand Down
32 changes: 13 additions & 19 deletions src/lib/button-toggle/button-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var _uniqueIdCounter = 0;

/** Change event object emitted by MdButtonToggle. */
export class MdButtonToggleChange {
source: MdButtonToggle;
source: MdButtonToggle|null;
value: any;
}

Expand All @@ -63,13 +63,13 @@ export class MdButtonToggleGroup implements AfterViewInit, ControlValueAccessor
private _name: string = `md-button-toggle-group-${_uniqueIdCounter++}`;

/** Disables all toggles in the group. */
private _disabled: boolean = null;
private _disabled: boolean|null = null;

/** Whether the button toggle group should be vertical. */
private _vertical: boolean = false;

/** The currently selected button toggle, should match the value. */
private _selected: MdButtonToggle = null;
private _selected: MdButtonToggle|null = null;

/** Whether the button toggle group is initialized or not. */
private _isInitialized: boolean = false;
Expand All @@ -91,7 +91,7 @@ export class MdButtonToggleGroup implements AfterViewInit, ControlValueAccessor

/** Child button toggle buttons. */
@ContentChildren(forwardRef(() => MdButtonToggle))
_buttonToggles: QueryList<MdButtonToggle> = null;
_buttonToggles: QueryList<MdButtonToggle>|null = null;

ngAfterViewInit() {
this._isInitialized = true;
Expand All @@ -110,7 +110,7 @@ export class MdButtonToggleGroup implements AfterViewInit, ControlValueAccessor

/** Whether the toggle group is disabled. */
@Input()
get disabled(): boolean {
get disabled(): boolean|null {
return this._disabled;
}

Expand Down Expand Up @@ -154,7 +154,7 @@ export class MdButtonToggleGroup implements AfterViewInit, ControlValueAccessor
return this._selected;
}

set selected(selected: MdButtonToggle) {
set selected(selected: MdButtonToggle|null) {
this._selected = selected;
this.value = selected ? selected.value : null;

Expand Down Expand Up @@ -245,27 +245,21 @@ export class MdButtonToggleGroup implements AfterViewInit, ControlValueAccessor
})
export class MdButtonToggleGroupMultiple {
/** Disables all toggles in the group. */
private _disabled: boolean = null;
private _disabled: boolean|null = null;

/** Whether the button toggle group should be vertical. */
private _vertical: boolean = false;

/** Whether the toggle group is disabled. */
@Input()
get disabled(): boolean {
return this._disabled;
}

get disabled(): boolean|null { return this._disabled; }
set disabled(value) {
this._disabled = (value != null && value !== false) ? true : null;
}

/** Whether the toggle group is vertical. */
@Input()
get vertical(): boolean {
return this._vertical;
}

get vertical(): boolean { return this._vertical; }
set vertical(value) {
this._vertical = coerceBooleanProperty(value);
}
Expand Down Expand Up @@ -299,13 +293,13 @@ export class MdButtonToggle implements OnInit {
name: string;

/** Whether or not this button toggle is disabled. */
private _disabled: boolean = null;
private _disabled: boolean|null = null;

/** Value assigned to this button toggle. */
private _value: any = null;

/** Whether or not the button toggle is a single selection. */
private _isSingleSelector: boolean = null;
private _isSingleSelector: boolean = false;

/** The parent button toggle group (exclusive selection). Optional. */
buttonToggleGroup: MdButtonToggleGroup;
Expand Down Expand Up @@ -413,12 +407,12 @@ export class MdButtonToggle implements OnInit {
/** Whether the button is disabled. */
@HostBinding('class.mat-button-toggle-disabled')
@Input()
get disabled(): boolean {
get disabled(): boolean|null {
return this._disabled || (this.buttonToggleGroup != null && this.buttonToggleGroup.disabled) ||
(this.buttonToggleGroupMultiple != null && this.buttonToggleGroupMultiple.disabled);
}

set disabled(value: boolean) {
set disabled(value: boolean|null) {
this._disabled = (value != null && value !== false) ? true : null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class MdButton {

/** Whether the ripple effect on click should be disabled. */
private _disableRipple: boolean = false;
private _disabled: boolean = null;
private _disabled: boolean|null = null;

/** Whether the ripple effect for this button is disabled. */
@Input()
Expand All @@ -122,7 +122,7 @@ export class MdButton {
/** Whether the button is disabled. */
@Input()
get disabled() { return this._disabled; }
set disabled(value: boolean) { this._disabled = coerceBooleanProperty(value) ? true : null; }
set disabled(value: boolean|null) { this._disabled = coerceBooleanProperty(value) ? true : null; }

constructor(private _elementRef: ElementRef, private _renderer: Renderer) { }

Expand Down
55 changes: 28 additions & 27 deletions src/lib/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class MdCheckbox implements ControlValueAccessor, AfterViewInit, OnDestro
/**
* Users can specify the `aria-labelledby` attribute which will be forwarded to the input element
*/
@Input('aria-labelledby') ariaLabelledby: string = null;
@Input('aria-labelledby') ariaLabelledby: string|null = null;

/** A unique id for the checkbox. If one is not supplied, it is auto-generated. */
@Input() id: string = `md-checkbox-${++nextId}`;
Expand Down Expand Up @@ -146,7 +146,7 @@ export class MdCheckbox implements ControlValueAccessor, AfterViewInit, OnDestro
@Input() tabIndex: number = 0;

/** Name value will be applied to the input element if present */
@Input() name: string = null;
@Input() name: string|null = null;

/** Event emitted when the checkbox's `checked` value changes. */
@Output() change: EventEmitter<MdCheckboxChange> = new EventEmitter<MdCheckboxChange>();
Expand Down Expand Up @@ -181,10 +181,10 @@ export class MdCheckbox implements ControlValueAccessor, AfterViewInit, OnDestro
private _controlValueAccessorChangeFn: (value: any) => void = (value) => {};

/** Reference to the focused state ripple. */
private _focusedRipple: RippleRef;
private _focusedRipple: RippleRef|null = null;

/** Reference to the focus origin monitor subscription. */
private _focusedSubscription: Subscription;
private _focusedSubscription: Subscription|null = null;

constructor(private _renderer: Renderer,
private _elementRef: ElementRef,
Expand Down Expand Up @@ -400,31 +400,32 @@ export class MdCheckbox implements ControlValueAccessor, AfterViewInit, OnDestro

private _getAnimationClassForCheckStateTransition(
oldState: TransitionCheckState, newState: TransitionCheckState): string {
var animSuffix: string;

let animSuffix = '';

switch (oldState) {
case TransitionCheckState.Init:
// Handle edge case where user interacts with checkbox that does not have [(ngModel)] or
// [checked] bound to it.
if (newState === TransitionCheckState.Checked) {
animSuffix = 'unchecked-checked';
} else if (newState == TransitionCheckState.Indeterminate) {
animSuffix = 'unchecked-indeterminate';
} else {
return '';
}
break;
case TransitionCheckState.Unchecked:
animSuffix = newState === TransitionCheckState.Checked ?
'unchecked-checked' : 'unchecked-indeterminate';
break;
case TransitionCheckState.Checked:
animSuffix = newState === TransitionCheckState.Unchecked ?
'checked-unchecked' : 'checked-indeterminate';
break;
case TransitionCheckState.Indeterminate:
animSuffix = newState === TransitionCheckState.Checked ?
'indeterminate-checked' : 'indeterminate-unchecked';
case TransitionCheckState.Init:
// Handle edge case where user interacts with checkbox that does not have [(ngModel)] or
// [checked] bound to it.
if (newState === TransitionCheckState.Checked) {
animSuffix = 'unchecked-checked';
} else if (newState == TransitionCheckState.Indeterminate) {
animSuffix = 'unchecked-indeterminate';
} else {
return '';
}
break;
case TransitionCheckState.Unchecked:
animSuffix = newState === TransitionCheckState.Checked ?
'unchecked-checked' : 'unchecked-indeterminate';
break;
case TransitionCheckState.Checked:
animSuffix = newState === TransitionCheckState.Unchecked ?
'checked-unchecked' : 'checked-indeterminate';
break;
case TransitionCheckState.Indeterminate:
animSuffix = newState === TransitionCheckState.Checked ?
'indeterminate-checked' : 'indeterminate-unchecked';
}

return `mat-checkbox-anim-${animSuffix}`;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/chips/chip-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class MdChipList implements AfterContentInit {
let focusedIndex = this._keyManager.activeItemIndex;

if (this._isValidIndex(focusedIndex)) {
let focusedChip: MdChip = this.chips.toArray()[focusedIndex];
let focusedChip: MdChip = this.chips.toArray()[focusedIndex as number];

if (focusedChip) {
focusedChip.toggleSelected();
Expand Down Expand Up @@ -201,8 +201,8 @@ export class MdChipList implements AfterContentInit {
* @param index The index to be checked.
* @returns True if the index is valid for our list of chips.
*/
private _isValidIndex(index: number): boolean {
return index >= 0 && index < this.chips.length;
private _isValidIndex(index: number|null): boolean {
return typeof index === 'number' && index >= 0 && index < this.chips.length;
}

}
6 changes: 3 additions & 3 deletions src/lib/chips/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface MdChipEvent {
export class MdChip implements Focusable, OnInit, OnDestroy {

/** Whether or not the chip is disabled. Disabled chips cannot be focused. */
protected _disabled: boolean = null;
protected _disabled: boolean|null = null;

/** Whether or not the chip is selected. */
protected _selected: boolean = false;
Expand Down Expand Up @@ -70,12 +70,12 @@ export class MdChip implements Focusable, OnInit, OnDestroy {
}

/** Whether or not the chip is disabled. */
@Input() get disabled(): boolean {
@Input() get disabled(): boolean|null {
return this._disabled;
}

/** Sets the disabled state of the chip. */
set disabled(value: boolean) {
set disabled(value: boolean|null) {
this._disabled = coerceBooleanProperty(value) ? true : null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/core/a11y/activedescendant-key-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ActiveDescendantKeyManager extends ListKeyManager<Highlightable> {
* It also adds active styles to the newly active item and removes active
* styles from the previously active item.
*/
setActiveItem(index: number): void {
setActiveItem(index: number|null): void {
if (this.activeItem) {
this.activeItem.setInactiveStyles();
}
Expand Down
7 changes: 5 additions & 2 deletions src/lib/core/a11y/focus-key-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ export class FocusKeyManager extends ListKeyManager<Focusable> {
* This method sets the active item to the item at the specified index.
* It also adds focuses the newly active item.
*/
setActiveItem(index: number): void {
setActiveItem(index: number|null): void {
super.setActiveItem(index);
this.activeItem.focus();

if (this.activeItem) {
this.activeItem.focus();
}
}

}
Loading