11// Local js definitions:
2- /* global addClass, getSettingValue, hasClass, searchState, updateLocalStorage */
2+ /* global addClass, getSettingValue, hasClass, updateLocalStorage */
33/* global onEachLazy, removeClass, getVar */
44
55"use strict" ;
@@ -121,12 +121,9 @@ function getNakedUrl() {
121121 * doesn't have a parent node.
122122 *
123123 * @param {HTMLElement } newNode
124- * @param {HTMLElement } referenceNode
124+ * @param {HTMLElement & { parentNode: HTMLElement } } referenceNode
125125 */
126126function insertAfter ( newNode , referenceNode ) {
127- // You're not allowed to pass an element with no parent.
128- // I dunno how to make TS's typechecker see that.
129- // @ts -expect-error
130127 referenceNode . parentNode . insertBefore ( newNode , referenceNode . nextSibling ) ;
131128}
132129
@@ -305,11 +302,10 @@ function preLoadCss(cssUrl) {
305302 window . searchState . timeout = null ;
306303 }
307304 } ,
308- // @ts -expect-error
309305 isDisplayed : ( ) => {
310306 const outputElement = window . searchState . outputElement ( ) ;
311- return outputElement &&
312- outputElement . parentElement &&
307+ return ! ! outputElement &&
308+ ! ! outputElement . parentElement &&
313309 outputElement . parentElement . id === ALTERNATIVE_DISPLAY_ID ;
314310 } ,
315311 // Sets the focus on the search bar at the top of the page
@@ -325,8 +321,6 @@ function preLoadCss(cssUrl) {
325321 search = window . searchState . outputElement ( ) ;
326322 }
327323 switchDisplayedElement ( search ) ;
328- // @ts -expect-error
329- window . searchState . mouseMovedAfterSearch = false ;
330324 document . title = window . searchState . title ;
331325 } ,
332326 removeQueryParameters : ( ) => {
@@ -503,43 +497,49 @@ function preLoadCss(cssUrl) {
503497 handleHashes ( ev ) ;
504498 }
505499
506- // @ts -expect-error
500+ /**
501+ * @param {HTMLElement|null } elem
502+ */
507503 function openParentDetails ( elem ) {
508504 while ( elem ) {
509505 if ( elem . tagName === "DETAILS" ) {
506+ // @ts -expect-error
510507 elem . open = true ;
511508 }
512- elem = elem . parentNode ;
509+ elem = elem . parentElement ;
513510 }
514511 }
515512
516- // @ts -expect-error
513+ /**
514+ * @param {string } id
515+ */
517516 function expandSection ( id ) {
518517 openParentDetails ( document . getElementById ( id ) ) ;
519518 }
520519
521- // @ts -expect-error
520+ /**
521+ * @param {KeyboardEvent } ev
522+ */
522523 function handleEscape ( ev ) {
523- // @ts -expect-error
524- searchState . clearInputTimeout ( ) ;
525- // @ts -expect-error
526- searchState . hideResults ( ) ;
524+ window . searchState . clearInputTimeout ( ) ;
525+ window . searchState . hideResults ( ) ;
527526 ev . preventDefault ( ) ;
528- // @ts -expect-error
529- searchState . defocus ( ) ;
527+ window . searchState . defocus ( ) ;
530528 window . hideAllModals ( true ) ; // true = reset focus for tooltips
531529 }
532530
533- // @ts -expect-error
531+ /**
532+ * @param {KeyboardEvent } ev
533+ */
534534 function handleShortcut ( ev ) {
535535 // Don't interfere with browser shortcuts
536536 const disableShortcuts = getSettingValue ( "disable-shortcuts" ) === "true" ;
537537 if ( ev . ctrlKey || ev . altKey || ev . metaKey || disableShortcuts ) {
538538 return ;
539539 }
540540
541- // @ts -expect-error
542- if ( document . activeElement . tagName === "INPUT" &&
541+ if ( document . activeElement &&
542+ document . activeElement . tagName === "INPUT" &&
543543 // @ts -expect-error
544544 document . activeElement . type !== "checkbox" &&
545545 // @ts -expect-error
@@ -559,8 +559,7 @@ function preLoadCss(cssUrl) {
559559 case "S" :
560560 case "/" :
561561 ev . preventDefault ( ) ;
562- // @ts -expect-error
563- searchState . focus ( ) ;
562+ window . searchState . focus ( ) ;
564563 break ;
565564
566565 case "+" :
@@ -586,7 +585,6 @@ function preLoadCss(cssUrl) {
586585 document . addEventListener ( "keydown" , handleShortcut ) ;
587586
588587 function addSidebarItems ( ) {
589- // @ts -expect-error
590588 if ( ! window . SIDEBAR_ITEMS ) {
591589 return ;
592590 }
@@ -675,7 +673,6 @@ function preLoadCss(cssUrl) {
675673 }
676674
677675 // <https://github.com/search?q=repo%3Arust-lang%2Frust+[RUSTDOCIMPL]+trait.impl&type=code>
678- // @ts -expect-error
679676 window . register_implementors = imp => {
680677 const implementors = document . getElementById ( "implementors-list" ) ;
681678 const synthetic_implementors = document . getElementById ( "synthetic-implementors-list" ) ;
@@ -767,9 +764,7 @@ function preLoadCss(cssUrl) {
767764 }
768765 }
769766 } ;
770- // @ts -expect-error
771767 if ( window . pending_implementors ) {
772- // @ts -expect-error
773768 window . register_implementors ( window . pending_implementors ) ;
774769 }
775770
@@ -802,16 +797,14 @@ function preLoadCss(cssUrl) {
802797 *
803798 * - After processing all of the impls, it sorts the sidebar items by name.
804799 *
805- * @param {{[cratename: string]: Array<Array<string|0>>} } imp
800+ * @param {rustdoc.TypeImpls } imp
806801 */
807- // @ts -expect-error
808802 window . register_type_impls = imp => {
809803 // @ts -expect-error
810804 if ( ! imp || ! imp [ window . currentCrate ] ) {
811805 return ;
812806 }
813- // @ts -expect-error
814- window . pending_type_impls = null ;
807+ window . pending_type_impls = undefined ;
815808 const idMap = new Map ( ) ;
816809
817810 let implementations = document . getElementById ( "implementations-list" ) ;
@@ -997,9 +990,7 @@ function preLoadCss(cssUrl) {
997990 list . replaceChildren ( ...newChildren ) ;
998991 }
999992 } ;
1000- // @ts -expect-error
1001993 if ( window . pending_type_impls ) {
1002- // @ts -expect-error
1003994 window . register_type_impls ( window . pending_type_impls ) ;
1004995 }
1005996
@@ -1695,8 +1686,7 @@ function preLoadCss(cssUrl) {
16951686 addSidebarCrates ( ) ;
16961687 onHashChange ( null ) ;
16971688 window . addEventListener ( "hashchange" , onHashChange ) ;
1698- // @ts -expect-error
1699- searchState . setup ( ) ;
1689+ window . searchState . setup ( ) ;
17001690} ( ) ) ;
17011691
17021692// Hide, show, and resize the sidebar
0 commit comments