@@ -528,8 +528,9 @@ export default class HTMLElement extends Node {
528
528
/**
529
529
* find element by it's id
530
530
* @param {string } id the id of the element to select
531
+ * @returns {HTMLElement | null } the element with the given id or null if not found
531
532
*/
532
- public getElementById ( id : string ) {
533
+ public getElementById ( id : string ) : HTMLElement | null {
533
534
const stack : Array < number > = [ ] ;
534
535
535
536
let currentNodeReference = this as Node ;
@@ -572,8 +573,9 @@ export default class HTMLElement extends Node {
572
573
/**
573
574
* traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor. If no such element exists, it returns null.
574
575
* @param selector a DOMString containing a selector list
576
+ * @returns {HTMLElement | null } the element with the given id or null if not found
575
577
*/
576
- public closest ( selector : string ) {
578
+ public closest ( selector : string ) : HTMLElement | null {
577
579
type Predicate = ( node : Node ) => node is HTMLElement ;
578
580
579
581
const mapChild = new Map < Node , Node > ( ) ;
@@ -642,17 +644,17 @@ export default class HTMLElement extends Node {
642
644
643
645
/**
644
646
* Get first child node
645
- * @return {Node } first child node
647
+ * @return {Node | undefined } first child node; or undefined if none
646
648
*/
647
- public get firstChild ( ) {
649
+ public get firstChild ( ) : Node | undefined {
648
650
return this . childNodes [ 0 ] ;
649
651
}
650
652
651
653
/**
652
654
* Get last child node
653
- * @return {Node } last child node
655
+ * @return {Node | undefined } last child node; or undefined if none
654
656
*/
655
- public get lastChild ( ) {
657
+ public get lastChild ( ) : Node | undefined {
656
658
return arr_back ( this . childNodes ) ;
657
659
}
658
660
@@ -737,7 +739,7 @@ export default class HTMLElement extends Node {
737
739
738
740
/**
739
741
* Get an attribute
740
- * @return {string } value of the attribute
742
+ * @return {string | undefined } value of the attribute; or undefined if not exist
741
743
*/
742
744
public getAttribute ( key : string ) : string | undefined {
743
745
return this . attrs [ key . toLowerCase ( ) ] ;
@@ -839,7 +841,7 @@ export default class HTMLElement extends Node {
839
841
// }
840
842
}
841
843
842
- public get nextSibling ( ) {
844
+ public get nextSibling ( ) : Node | null {
843
845
if ( this . parentNode ) {
844
846
const children = this . parentNode . childNodes ;
845
847
let i = 0 ;
@@ -851,7 +853,7 @@ export default class HTMLElement extends Node {
851
853
}
852
854
}
853
855
854
- public get nextElementSibling ( ) : HTMLElement {
856
+ public get nextElementSibling ( ) : HTMLElement | null {
855
857
if ( this . parentNode ) {
856
858
const children = this . parentNode . childNodes ;
857
859
let i = 0 ;
@@ -870,7 +872,7 @@ export default class HTMLElement extends Node {
870
872
}
871
873
}
872
874
873
- public get previousSibling ( ) {
875
+ public get previousSibling ( ) : Node | null {
874
876
if ( this . parentNode ) {
875
877
const children = this . parentNode . childNodes ;
876
878
let i = children . length ;
@@ -882,7 +884,7 @@ export default class HTMLElement extends Node {
882
884
}
883
885
}
884
886
885
- public get previousElementSibling ( ) : HTMLElement {
887
+ public get previousElementSibling ( ) : HTMLElement | null {
886
888
if ( this . parentNode ) {
887
889
const children = this . parentNode . childNodes ;
888
890
let i = children . length ;
0 commit comments