@@ -528,8 +528,9 @@ export default class HTMLElement extends Node {
528528 /**
529529 * find element by it's id
530530 * @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
531532 */
532- public getElementById ( id : string ) {
533+ public getElementById ( id : string ) : HTMLElement | null {
533534 const stack : Array < number > = [ ] ;
534535
535536 let currentNodeReference = this as Node ;
@@ -572,8 +573,9 @@ export default class HTMLElement extends Node {
572573 /**
573574 * 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.
574575 * @param selector a DOMString containing a selector list
576+ * @returns {HTMLElement | null } the element with the given id or null if not found
575577 */
576- public closest ( selector : string ) {
578+ public closest ( selector : string ) : HTMLElement | null {
577579 type Predicate = ( node : Node ) => node is HTMLElement ;
578580
579581 const mapChild = new Map < Node , Node > ( ) ;
@@ -642,17 +644,17 @@ export default class HTMLElement extends Node {
642644
643645 /**
644646 * Get first child node
645- * @return {Node } first child node
647+ * @return {Node | undefined } first child node; or undefined if none
646648 */
647- public get firstChild ( ) {
649+ public get firstChild ( ) : Node | undefined {
648650 return this . childNodes [ 0 ] ;
649651 }
650652
651653 /**
652654 * Get last child node
653- * @return {Node } last child node
655+ * @return {Node | undefined } last child node; or undefined if none
654656 */
655- public get lastChild ( ) {
657+ public get lastChild ( ) : Node | undefined {
656658 return arr_back ( this . childNodes ) ;
657659 }
658660
@@ -735,7 +737,7 @@ export default class HTMLElement extends Node {
735737
736738 /**
737739 * Get an attribute
738- * @return {string } value of the attribute
740+ * @return {string | undefined } value of the attribute; or undefined if not exist
739741 */
740742 public getAttribute ( key : string ) : string | undefined {
741743 return this . attrs [ key . toLowerCase ( ) ] ;
@@ -837,7 +839,7 @@ export default class HTMLElement extends Node {
837839 // }
838840 }
839841
840- public get nextSibling ( ) {
842+ public get nextSibling ( ) : Node | null {
841843 if ( this . parentNode ) {
842844 const children = this . parentNode . childNodes ;
843845 let i = 0 ;
@@ -849,7 +851,7 @@ export default class HTMLElement extends Node {
849851 }
850852 }
851853
852- public get nextElementSibling ( ) : HTMLElement {
854+ public get nextElementSibling ( ) : HTMLElement | null {
853855 if ( this . parentNode ) {
854856 const children = this . parentNode . childNodes ;
855857 let i = 0 ;
@@ -868,7 +870,7 @@ export default class HTMLElement extends Node {
868870 }
869871 }
870872
871- public get previousSibling ( ) {
873+ public get previousSibling ( ) : Node | null {
872874 if ( this . parentNode ) {
873875 const children = this . parentNode . childNodes ;
874876 let i = children . length ;
@@ -880,7 +882,7 @@ export default class HTMLElement extends Node {
880882 }
881883 }
882884
883- public get previousElementSibling ( ) : HTMLElement {
885+ public get previousElementSibling ( ) : HTMLElement | null {
884886 if ( this . parentNode ) {
885887 const children = this . parentNode . childNodes ;
886888 let i = children . length ;
0 commit comments