diff options
author | 杨宇千 <crupest@outlook.com> | 2019-03-11 21:30:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-11 21:30:22 +0800 |
commit | 4535d1fd30eb02b3fe60718235a0725e3b30049e (patch) | |
tree | d9d2ea66bb3b5586b3e0f9ac390dc3ac96096e2e /Timeline/ClientApp/src/app/utilities | |
parent | 8caef17dd3e455de27f44d13751c27ee4dfe2e1e (diff) | |
parent | 87f7b00f9414b7633a080838a725a687461efd68 (diff) | |
download | timeline-4535d1fd30eb02b3fe60718235a0725e3b30049e.tar.gz timeline-4535d1fd30eb02b3fe60718235a0725e3b30049e.tar.bz2 timeline-4535d1fd30eb02b3fe60718235a0725e3b30049e.zip |
Merge pull request #12 from crupest/strict
Use strict check of typescript compiler.
Diffstat (limited to 'Timeline/ClientApp/src/app/utilities')
3 files changed, 20 insertions, 7 deletions
diff --git a/Timeline/ClientApp/src/app/utilities/debounce-click.directive.spec.ts b/Timeline/ClientApp/src/app/utilities/debounce-click.directive.spec.ts index 75710d0c..89f66b99 100644 --- a/Timeline/ClientApp/src/app/utilities/debounce-click.directive.spec.ts +++ b/Timeline/ClientApp/src/app/utilities/debounce-click.directive.spec.ts @@ -13,8 +13,8 @@ interface TestComponent { template: '<button (appDebounceClick)="clickHandler()"></button>' }) class DefaultDebounceTimeTestComponent { - @ViewChild(DebounceClickDirective) - directive: DebounceClickDirective; + + @ViewChild(DebounceClickDirective) directive!: DebounceClickDirective; clickHandler: () => void = () => { }; } @@ -24,10 +24,9 @@ class DefaultDebounceTimeTestComponent { template: '<button (appDebounceClick)="clickHandler()" [appDebounceClickTime]="debounceTime"></button>' }) class CustomDebounceTimeTestComponent { - debounceTime: number; + debounceTime: number | undefined; - @ViewChild(DebounceClickDirective) - directive: DebounceClickDirective; + @ViewChild(DebounceClickDirective) directive!: DebounceClickDirective; clickHandler: () => void = () => { }; } diff --git a/Timeline/ClientApp/src/app/utilities/debounce-click.directive.ts b/Timeline/ClientApp/src/app/utilities/debounce-click.directive.ts index feb0404e..1d01b671 100644 --- a/Timeline/ClientApp/src/app/utilities/debounce-click.directive.ts +++ b/Timeline/ClientApp/src/app/utilities/debounce-click.directive.ts @@ -7,7 +7,7 @@ import { debounceTime } from 'rxjs/operators'; }) export class DebounceClickDirective implements OnInit, OnDestroy { - private subscription: Subscription; + private subscription: Subscription | undefined; @Output('appDebounceClick') clickEvent = new EventEmitter<any>(); @@ -34,6 +34,8 @@ export class DebounceClickDirective implements OnInit, OnDestroy { } ngOnDestroy() { - this.subscription.unsubscribe(); + if (this.subscription) { + this.subscription.unsubscribe(); + } } } diff --git a/Timeline/ClientApp/src/app/utilities/language-untilities.ts b/Timeline/ClientApp/src/app/utilities/language-untilities.ts new file mode 100644 index 00000000..be9df2dc --- /dev/null +++ b/Timeline/ClientApp/src/app/utilities/language-untilities.ts @@ -0,0 +1,12 @@ +export function nullIfUndefined<T>(value: T | undefined): T | null { + return value === undefined ? null : value; +} + +export function throwIfNullOrUndefined<T>(value: T | null | undefined, + lazyMessage: () => string = () => 'Value mustn\'t be falsy'): T | never { + if (value === null || value === undefined) { + throw new Error(lazyMessage()); + } else { + return value; + } +} |