@@ -20,7 +20,7 @@ export function clearNode(node: HTMLElement): void {
20
20
}
21
21
}
22
22
23
- export function isInDOM ( node : Node ) : boolean {
23
+ export function isInDOM ( node : Node | null ) : boolean {
24
24
while ( node ) {
25
25
if ( node === document . body ) {
26
26
return true ;
@@ -151,7 +151,7 @@ const _manualClassList = new class implements IDomClassList {
151
151
152
152
const _nativeClassList = new class implements IDomClassList {
153
153
hasClass ( node : HTMLElement , className : string ) : boolean {
154
- return className && node . classList && node . classList . contains ( className ) ;
154
+ return Boolean ( className ) && node . classList && node . classList . contains ( className ) ;
155
155
}
156
156
157
157
addClasses ( node : HTMLElement , ...classNames : string [ ] ) : void {
@@ -198,7 +198,7 @@ class DomListener implements IDisposable {
198
198
private readonly _type : string ;
199
199
private readonly _useCapture : boolean ;
200
200
201
- constructor ( node : Element | Window | Document , type : string , handler : ( e : any ) => void , useCapture : boolean ) {
201
+ constructor ( node : Element | Window | Document , type : string , handler : ( e : any ) => void , useCapture ? : boolean ) {
202
202
this . _node = node ;
203
203
this . _type = type ;
204
204
this . _handler = handler ;
@@ -215,8 +215,8 @@ class DomListener implements IDisposable {
215
215
this . _node . removeEventListener ( this . _type , this . _handler , this . _useCapture ) ;
216
216
217
217
// Prevent leakers from holding on to the dom or handler func
218
- this . _node = null ;
219
- this . _handler = null ;
218
+ this . _node = null ! ;
219
+ this . _handler = null ! ;
220
220
}
221
221
}
222
222
@@ -257,7 +257,7 @@ export let addStandardDisposableListener: IAddStandardDisposableListenerSignatur
257
257
export function addDisposableNonBubblingMouseOutListener ( node : Element , handler : ( event : MouseEvent ) => void ) : IDisposable {
258
258
return addDisposableListener ( node , 'mouseout' , ( e : MouseEvent ) => {
259
259
// Mouse out bubbles, so this is an attempt to ignore faux mouse outs coming from children elements
260
- let toElement = < Node > ( e . relatedTarget || e . toElement ) ;
260
+ let toElement : Node | null = < Node > ( e . relatedTarget || e . toElement ) ;
261
261
while ( toElement && toElement !== node ) {
262
262
toElement = toElement . parentNode ;
263
263
}
@@ -311,7 +311,7 @@ class AnimationFrameQueueItem implements IDisposable {
311
311
public priority : number ;
312
312
private _canceled : boolean ;
313
313
314
- constructor ( runner : ( ) => void , priority : number ) {
314
+ constructor ( runner : ( ) => void , priority : number = 0 ) {
315
315
this . _runner = runner ;
316
316
this . priority = priority ;
317
317
this . _canceled = false ;
@@ -366,7 +366,7 @@ class AnimationFrameQueueItem implements IDisposable {
366
366
inAnimationFrameRunner = true ;
367
367
while ( CURRENT_QUEUE . length > 0 ) {
368
368
CURRENT_QUEUE . sort ( AnimationFrameQueueItem . sort ) ;
369
- let top = CURRENT_QUEUE . shift ( ) ;
369
+ let top = CURRENT_QUEUE . shift ( ) ! ;
370
370
top . execute ( ) ;
371
371
}
372
372
inAnimationFrameRunner = false ;
@@ -387,7 +387,7 @@ class AnimationFrameQueueItem implements IDisposable {
387
387
runAtThisOrScheduleAtNextAnimationFrame = ( runner : ( ) => void , priority ?: number ) => {
388
388
if ( inAnimationFrameRunner ) {
389
389
let item = new AnimationFrameQueueItem ( runner , priority ) ;
390
- CURRENT_QUEUE . push ( item ) ;
390
+ CURRENT_QUEUE ! . push ( item ) ;
391
391
return item ;
392
392
} else {
393
393
return scheduleAtNextAnimationFrame ( runner , priority ) ;
@@ -407,7 +407,7 @@ export function modify(callback: () => void): IDisposable {
407
407
* Add a throttled listener. `handler` is fired at most every 16ms or with the next animation frame (if browser supports it).
408
408
*/
409
409
export interface IEventMerger < R , E > {
410
- ( lastEvent : R , currentEvent : E ) : R ;
410
+ ( lastEvent : R | null , currentEvent : E ) : R ;
411
411
}
412
412
413
413
export interface DOMEvent {
@@ -431,7 +431,7 @@ class TimeoutThrottledDomListener<R, E extends DOMEvent> extends Disposable {
431
431
432
432
let invokeHandler = ( ) => {
433
433
lastHandlerTime = ( new Date ( ) ) . getTime ( ) ;
434
- handler ( lastEvent ) ;
434
+ handler ( < R > lastEvent ) ;
435
435
lastEvent = null ;
436
436
} ;
437
437
@@ -455,7 +455,7 @@ export function addDisposableThrottledListener<R, E extends DOMEvent = DOMEvent>
455
455
}
456
456
457
457
export function getComputedStyle ( el : HTMLElement ) : CSSStyleDeclaration {
458
- return document . defaultView . getComputedStyle ( el , null ) ;
458
+ return document . defaultView ! . getComputedStyle ( el , null ) ;
459
459
}
460
460
461
461
// Adapted from WinJS
@@ -660,7 +660,7 @@ export const StandardWindow: IStandardWindow = new class implements IStandardWin
660
660
// modern browsers
661
661
return window . scrollX ;
662
662
} else {
663
- return document . body . scrollLeft + document . documentElement . scrollLeft ;
663
+ return document . body . scrollLeft + document . documentElement ! . scrollLeft ;
664
664
}
665
665
}
666
666
@@ -669,7 +669,7 @@ export const StandardWindow: IStandardWindow = new class implements IStandardWin
669
669
// modern browsers
670
670
return window . scrollY ;
671
671
} else {
672
- return document . body . scrollTop + document . documentElement . scrollTop ;
672
+ return document . body . scrollTop + document . documentElement ! . scrollTop ;
673
673
}
674
674
}
675
675
} ;
@@ -728,7 +728,7 @@ export function getLargestChildWidth(parent: HTMLElement, children: HTMLElement[
728
728
729
729
// ----------------------------------------------------------------------------------------
730
730
731
- export function isAncestor ( testChild : Node , testAncestor : Node ) : boolean {
731
+ export function isAncestor ( testChild : Node | null , testAncestor : Node ) : boolean {
732
732
while ( testChild ) {
733
733
if ( testChild === testAncestor ) {
734
734
return true ;
@@ -739,7 +739,7 @@ export function isAncestor(testChild: Node, testAncestor: Node): boolean {
739
739
return false ;
740
740
}
741
741
742
- export function findParentWithClass ( node : HTMLElement , clazz : string , stopAtClazzOrNode ?: string | HTMLElement ) : HTMLElement {
742
+ export function findParentWithClass ( node : HTMLElement , clazz : string , stopAtClazzOrNode ?: string | HTMLElement ) : HTMLElement | null {
743
743
while ( node ) {
744
744
if ( hasClass ( node , clazz ) ) {
745
745
return node ;
@@ -1002,17 +1002,18 @@ export function $<T extends HTMLElement>(description: string, attrs?: { [key: st
1002
1002
result . className = match [ 4 ] . replace ( / \. / g, ' ' ) . trim ( ) ;
1003
1003
}
1004
1004
1005
- Object . keys ( attrs || { } ) . forEach ( name => {
1005
+ attrs = attrs || { } ;
1006
+ Object . keys ( attrs ) . forEach ( name => {
1007
+ const value = attrs ! [ name ] ;
1006
1008
if ( / ^ o n \w + $ / . test ( name ) ) {
1007
- ( < any > result ) [ name ] = attrs [ name ] ;
1009
+ ( < any > result ) [ name ] = value ;
1008
1010
} else if ( name === 'selected' ) {
1009
- const value = attrs [ name ] ;
1010
1011
if ( value ) {
1011
1012
result . setAttribute ( name , 'true' ) ;
1012
1013
}
1013
1014
1014
1015
} else {
1015
- result . setAttribute ( name , attrs [ name ] ) ;
1016
+ result . setAttribute ( name , value ) ;
1016
1017
}
1017
1018
} ) ;
1018
1019
@@ -1061,7 +1062,7 @@ export function hide(...elements: HTMLElement[]): void {
1061
1062
}
1062
1063
}
1063
1064
1064
- function findParentWithAttribute ( node : Node , attribute : string ) : HTMLElement {
1065
+ function findParentWithAttribute ( node : Node | null , attribute : string ) : HTMLElement | null {
1065
1066
while ( node ) {
1066
1067
if ( node instanceof HTMLElement && node . hasAttribute ( attribute ) ) {
1067
1068
return node ;
0 commit comments