@@ -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
@@ -735,7 +737,7 @@ export default class HTMLElement extends Node {
735
737
736
738
/**
737
739
* Get an attribute
738
- * @return {string } value of the attribute
740
+ * @return {string | undefined } value of the attribute; or undefined if not exist
739
741
*/
740
742
public getAttribute ( key : string ) : string | undefined {
741
743
return this . attrs [ key . toLowerCase ( ) ] ;
@@ -837,7 +839,7 @@ export default class HTMLElement extends Node {
837
839
// }
838
840
}
839
841
840
- public get nextSibling ( ) {
842
+ public get nextSibling ( ) : Node | null {
841
843
if ( this . parentNode ) {
842
844
const children = this . parentNode . childNodes ;
843
845
let i = 0 ;
@@ -849,7 +851,7 @@ export default class HTMLElement extends Node {
849
851
}
850
852
}
851
853
852
- public get nextElementSibling ( ) : HTMLElement {
854
+ public get nextElementSibling ( ) : HTMLElement | null {
853
855
if ( this . parentNode ) {
854
856
const children = this . parentNode . childNodes ;
855
857
let i = 0 ;
@@ -868,7 +870,7 @@ export default class HTMLElement extends Node {
868
870
}
869
871
}
870
872
871
- public get previousSibling ( ) {
873
+ public get previousSibling ( ) : Node | null {
872
874
if ( this . parentNode ) {
873
875
const children = this . parentNode . childNodes ;
874
876
let i = children . length ;
@@ -880,7 +882,7 @@ export default class HTMLElement extends Node {
880
882
}
881
883
}
882
884
883
- public get previousElementSibling ( ) : HTMLElement {
885
+ public get previousElementSibling ( ) : HTMLElement | null {
884
886
if ( this . parentNode ) {
885
887
const children = this . parentNode . childNodes ;
886
888
let i = children . length ;
0 commit comments