Skip to content

Commit

Permalink
build: add strictNullCheck config
Browse files Browse the repository at this point in the history
  • Loading branch information
Wendell committed Mar 12, 2019
1 parent c598214 commit 03aa3bf
Show file tree
Hide file tree
Showing 229 changed files with 1,457 additions and 1,467 deletions.
12 changes: 6 additions & 6 deletions components/affix/affix.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ describe('affix', () => {
setupInitialState();
emitScroll(target, 5000);
const wrapEl = componentObject.wrap();
expect(+wrapEl.style.bottom.replace('px', '')).toBe(0);
expect(+wrapEl.style.bottom!.replace('px', '')).toBe(0);

discardPeriodicTasks();
}));
Expand All @@ -259,7 +259,7 @@ describe('affix', () => {
setupInitialState();
emitScroll(target, 0);
const wrapEl = componentObject.wrap();
expect(+wrapEl.style.bottom.replace('px', '')).toBeGreaterThan(0);
expect(+wrapEl.style.bottom!.replace('px', '')).toBeGreaterThan(0);

discardPeriodicTasks();
}));
Expand All @@ -270,7 +270,7 @@ describe('affix', () => {
setupInitialState();
emitScroll(target, 5000);
const wrapEl = componentObject.wrap();
expect(+wrapEl.style.bottom.replace('px', '')).toBe(0);
expect(+wrapEl.style.bottom!.replace('px', '')).toBe(0);

discardPeriodicTasks();
}));
Expand Down Expand Up @@ -432,7 +432,7 @@ describe('affix', () => {
return debugElement.query(By.css('#target')).nativeElement;
}

private getKey(el: Element | Window): string {
private getKey(el?: Element | Window): string {
let key: string;
if (el instanceof Window) {
key = 'window';
Expand Down Expand Up @@ -497,7 +497,7 @@ describe('affix-extra', () => {
window.dispatchEvent(new Event('scroll'));
tick(30);
fixture.detectChanges();
const ret = +(el.querySelector('.ant-affix') as HTMLElement).style.bottom.replace('px', '');
const ret = +(el.querySelector('.ant-affix') as HTMLElement).style.bottom!.replace('px', '');
expect(ret).toBe(value);
}));
});
Expand All @@ -516,7 +516,7 @@ describe('affix-extra', () => {
class TestAffixComponent {
@ViewChild(NzAffixComponent)
nzAffixComponent: NzAffixComponent;
fakeTarget: string | Element | Window = null;
fakeTarget: string | Element | Window | null = null;
newOffset: {};
newOffsetBottom: {};
}
53 changes: 25 additions & 28 deletions components/affix/nz-affix.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@angular/core';

import { NzScrollService } from '../core/scroll/nz-scroll.service';
import { NGStyleInterface } from '../core/types/ng-class';
import { shallowEqual } from '../core/util/check';
import { toNumber } from '../core/util/convert';
import { throttleByAnimationFrameDecorator } from '../core/util/throttleByAnimationFrame';
Expand All @@ -40,15 +41,15 @@ export class NzAffixComponent implements OnInit, OnDestroy {
}

@Input()
set nzOffsetTop(value: number) {
if (typeof value === 'undefined') {
set nzOffsetTop(value: number | null) {
if (value === undefined || value === null) {
return;
}
this._offsetTop = toNumber(value, null);
this.updatePosition({} as Event);
}

get nzOffsetTop(): number {
get nzOffsetTop(): number | null {
return this._offsetTop;
}

Expand All @@ -61,13 +62,7 @@ export class NzAffixComponent implements OnInit, OnDestroy {
this.updatePosition({} as Event);
}

@Output()
readonly nzChange: EventEmitter<boolean> = new EventEmitter();

// tslint:disable-next-line:no-any
constructor(_el: ElementRef, private scrollSrv: NzScrollService, @Inject(DOCUMENT) private doc: any) {
this.placeholderNode = _el.nativeElement;
}
@Output() readonly nzChange = new EventEmitter<boolean>();

private timeout: number;
private readonly events = [
Expand All @@ -80,17 +75,19 @@ export class NzAffixComponent implements OnInit, OnDestroy {
'load'
];
@ViewChild('fixedEl') private fixedEl: ElementRef;
// tslint:disable-next-line:no-any
private affixStyle: any;
// tslint:disable-next-line:no-any
private placeholderStyle: any;
private placeholderNode: HTMLElement;

private _target: Element | Window = window;
private readonly placeholderNode: HTMLElement;

private _offsetTop: number;
private affixStyle: NGStyleInterface | undefined;
private placeholderStyle: NGStyleInterface | undefined;
private _target: Element | Window = window;
private _offsetTop: number | null;
private _offsetBottom: number | null;

private _offsetBottom: number;
// tslint:disable-next-line:no-any
constructor(_el: ElementRef, private scrollSrv: NzScrollService, @Inject(DOCUMENT) private doc: any) {
this.placeholderNode = _el.nativeElement;
}

ngOnInit(): void {
this.timeout = setTimeout(() => {
Expand All @@ -106,7 +103,7 @@ export class NzAffixComponent implements OnInit, OnDestroy {
(this.updatePosition as any).cancel();
}

getOffset(element: Element, target: Element | Window | null): {
getOffset(element: Element, target: Element | Window | undefined): {
top: number;
left: number;
width: number;
Expand Down Expand Up @@ -143,14 +140,14 @@ export class NzAffixComponent implements OnInit, OnDestroy {
});
}

private getTargetRect(target: Element | Window | null): ClientRect {
private getTargetRect(target: Element | Window | undefined): ClientRect {
return target !== window ?
(target as HTMLElement).getBoundingClientRect() :
{ top: 0, left: 0, bottom: 0 } as ClientRect;
}

private genStyle(affixStyle: {}): string {
if (affixStyle == null) {
private genStyle(affixStyle?: NGStyleInterface): string {
if (!affixStyle) {
return '';
}
return Object.keys(affixStyle).map(key => {
Expand All @@ -159,7 +156,7 @@ export class NzAffixComponent implements OnInit, OnDestroy {
}).join(';');
}

private setAffixStyle(e: Event, affixStyle: {}): void {
private setAffixStyle(e: Event, affixStyle?: NGStyleInterface): void {
const originalAffixStyle = this.affixStyle;
const isWindow = this._target === window;
if (e.type === 'scroll' && originalAffixStyle && affixStyle && isWindow) {
Expand All @@ -185,7 +182,7 @@ export class NzAffixComponent implements OnInit, OnDestroy {
}
}

private setPlaceholderStyle(placeholderStyle: {}): void {
private setPlaceholderStyle(placeholderStyle?: NGStyleInterface): void {
const originalPlaceholderStyle = this.placeholderStyle;
if (shallowEqual(placeholderStyle, originalPlaceholderStyle)) {
return;
Expand All @@ -196,7 +193,7 @@ export class NzAffixComponent implements OnInit, OnDestroy {

private syncPlaceholderStyle(e: Event): void {
if (!this.affixStyle) {
return ;
return;
}
this.placeholderNode.style.cssText = '';
const widthObj = { width: this.placeholderNode.offsetWidth };
Expand Down Expand Up @@ -233,7 +230,7 @@ export class NzAffixComponent implements OnInit, OnDestroy {
}
const targetRect = this.getTargetRect(targetNode);
const targetInnerHeight =
(targetNode as Window).innerHeight || (targetNode as HTMLElement).clientHeight;
(targetNode as Window).innerHeight || (targetNode as HTMLElement).clientHeight;
if (scrollTop >= elemOffset.top - (offsetTop as number) && offsetMode.top) {
const width = elemOffset.width;
const top = targetRect.top + (offsetTop as number);
Expand Down Expand Up @@ -268,9 +265,9 @@ export class NzAffixComponent implements OnInit, OnDestroy {
if (e.type === 'resize' && this.affixStyle && this.affixStyle.position === 'fixed' && this.placeholderNode.offsetWidth) {
this.setAffixStyle(e, { ...this.affixStyle, width: this.placeholderNode.offsetWidth });
} else {
this.setAffixStyle(e, null);
this.setAffixStyle(e);
}
this.setPlaceholderStyle(null);
this.setPlaceholderStyle();
}

if (e.type === 'resize') {
Expand Down
6 changes: 3 additions & 3 deletions components/alert/nz-alert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ describe('alert', () => {
});
it('should className correct', () => {
fixture.detectChanges();
expect(alert.nativeElement.firstElementChild.classList).toContain('ant-alert');
expect(alert.nativeElement.firstElementChild!.classList).toContain('ant-alert');
});
it('should banner work', () => {
fixture.detectChanges();
expect(alert.nativeElement.firstElementChild.classList).not.toContain('ant-alert-banner');
expect(alert.nativeElement.firstElementChild!.classList).not.toContain('ant-alert-banner');
expect(alert.nativeElement.querySelector('.ant-alert').classList).toContain(`ant-alert-info`);
expect(alert.nativeElement.querySelector('.ant-alert-icon')).toBeNull();
testComponent.banner = true;
fixture.detectChanges();
expect(alert.nativeElement.firstElementChild.classList).toContain('ant-alert-banner');
expect(alert.nativeElement.firstElementChild!.classList).toContain('ant-alert-banner');
expect(alert.nativeElement.querySelector('.ant-alert').classList).toContain(`ant-alert-info`);
expect(alert.nativeElement.querySelector('.ant-alert-icon')).toBeNull();
});
Expand Down
21 changes: 11 additions & 10 deletions components/anchor/anchor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NzAnchorComponent } from './nz-anchor.component';
import { NzScrollService } from '../core/scroll/nz-scroll.service';

const throttleTime = 51;

describe('anchor', () => {
let fixture: ComponentFixture<TestComponent>;
let dl: DebugElement;
Expand Down Expand Up @@ -36,26 +37,26 @@ describe('anchor', () => {
_easing?: any,
callback?: () => void
) => {
callback();
if (callback) { callback(); }
});
expect(context._scroll).not.toHaveBeenCalled();
page.to('#何时使用');
expect(context._scroll).toHaveBeenCalled();
});

it('should hava remove listen when the component is destroyed', () => {
expect(context.comp['scroll$'].closed).toBeFalsy();
expect(context.comp['scroll$']!.closed).toBeFalsy();
context.comp.ngOnDestroy();
fixture.detectChanges();
expect(context.comp['scroll$'].closed).toBeTruthy();
expect(context.comp['scroll$']!.closed).toBeTruthy();
});

it('should actived when scrolling to the anchor', (done: () => void) => {
expect(context._scroll).not.toHaveBeenCalled();
page.scrollTo();
setTimeout(() => {
const inkNode = page.getEl('.ant-anchor-ink-ball');
expect(+inkNode.style.top.replace('px', '')).toBeGreaterThan(0);
expect(+inkNode.style.top!.replace('px', '')).toBeGreaterThan(0);
expect(context._scroll).toHaveBeenCalled();
done();
}, throttleTime);
Expand All @@ -71,14 +72,14 @@ describe('anchor', () => {
window.dispatchEvent(new Event('scroll'));
tick(throttleTime);
fixture.detectChanges();
expect(context.comp['clearActive']).toHaveBeenCalled();
expect(context.comp['clearActive']!).toHaveBeenCalled();
}));

it(`won't scolling when is not exists link`, () => {
spyOn(srv, 'getScroll');
expect(context._scroll).not.toHaveBeenCalled();
expect(srv.getScroll).not.toHaveBeenCalled();
page.to('#invalid');
page!.to('#invalid');
expect(srv.getScroll).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -159,7 +160,7 @@ describe('anchor', () => {
expect(window.addEventListener).toHaveBeenCalled();
});
it('with string', () => {
const el = document.querySelector('#target');
const el = document.querySelector('#target')!;
spyOn(el, 'addEventListener');
context.nzTarget = '#target';
fixture.detectChanges();
Expand Down Expand Up @@ -189,9 +190,9 @@ describe('anchor', () => {

describe('**boundary**', () => {
it('#getOffsetTop', (done: () => void) => {
const el1 = document.getElementById('何时使用');
const el1 = document.getElementById('何时使用')!;
spyOn(el1, 'getClientRects').and.returnValue([]);
const el2 = document.getElementById('parallel1');
const el2 = document.getElementById('parallel1')!;
spyOn(el2, 'getBoundingClientRect').and.returnValue({
top: 0
});
Expand Down Expand Up @@ -280,7 +281,7 @@ export class TestComponent {
nzBounds = 5;
nzOffsetTop = 0;
nzShowInkInFixed = false;
nzTarget = null;
nzTarget: any = null;
_click() {}
_scroll() {}
}
2 changes: 1 addition & 1 deletion components/anchor/nz-anchor-link.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class NzAnchorLinkComponent implements OnInit, OnDestroy {

@Input() nzHref = '#';

titleStr = '';
titleStr: string | null = '';
titleTpl: TemplateRef<void>;
active: boolean = false;

Expand Down
Loading

0 comments on commit 03aa3bf

Please sign in to comment.