@@ -407,9 +407,7 @@ function preLoadCss(cssUrl) {
407
407
function loadSearch ( ) {
408
408
if ( ! searchLoaded ) {
409
409
searchLoaded = true ;
410
- // @ts -expect-error
411
410
window . rr_ = data => {
412
- // @ts -expect-error
413
411
window . searchIndex = data ;
414
412
} ;
415
413
if ( ! window . StringdexOnload ) {
@@ -1277,13 +1275,11 @@ function preLoadCss(cssUrl) {
1277
1275
}
1278
1276
1279
1277
window . addEventListener ( "resize" , ( ) => {
1280
- // @ts -expect-error
1281
1278
if ( window . CURRENT_TOOLTIP_ELEMENT ) {
1282
1279
// As a workaround to the behavior of `contains: layout` used in doc togglers,
1283
1280
// tooltip popovers are positioned using javascript.
1284
1281
//
1285
1282
// This means when the window is resized, we need to redo the layout.
1286
- // @ts -expect-error
1287
1283
const base = window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE ;
1288
1284
const force_visible = base . TOOLTIP_FORCE_VISIBLE ;
1289
1285
hideTooltip ( false ) ;
@@ -1329,26 +1325,25 @@ function preLoadCss(cssUrl) {
1329
1325
*/
1330
1326
function showTooltip ( e ) {
1331
1327
const notable_ty = e . getAttribute ( "data-notable-ty" ) ;
1332
- // @ts -expect-error
1333
1328
if ( ! window . NOTABLE_TRAITS && notable_ty ) {
1334
1329
const data = document . getElementById ( "notable-traits-data" ) ;
1335
1330
if ( data ) {
1336
- // @ts -expect-error
1337
1331
window . NOTABLE_TRAITS = JSON . parse ( data . innerText ) ;
1338
1332
} else {
1339
1333
throw new Error ( "showTooltip() called with notable without any notable traits!" ) ;
1340
1334
}
1341
1335
}
1342
1336
// Make this function idempotent. If the tooltip is already shown, avoid doing extra work
1343
1337
// and leave it alone.
1344
- // @ts -expect-error
1345
1338
if ( window . CURRENT_TOOLTIP_ELEMENT && window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE === e ) {
1346
- // @ts -expect-error
1347
1339
clearTooltipHoverTimeout ( window . CURRENT_TOOLTIP_ELEMENT ) ;
1348
1340
return ;
1349
1341
}
1350
1342
window . hideAllModals ( false ) ;
1351
- const wrapper = document . createElement ( "div" ) ;
1343
+ // use Object.assign to make sure the object has the correct type
1344
+ // with all of the correct fields before it is assigned to a variable,
1345
+ // as typescript has no way to change the type of a variable once it is initialized.
1346
+ const wrapper = Object . assign ( document . createElement ( "div" ) , { TOOLTIP_BASE : e } ) ;
1352
1347
if ( notable_ty ) {
1353
1348
wrapper . innerHTML = "<div class=\"content\">" +
1354
1349
// @ts -expect-error
@@ -1394,11 +1389,7 @@ function preLoadCss(cssUrl) {
1394
1389
) ;
1395
1390
}
1396
1391
wrapper . style . visibility = "" ;
1397
- // @ts -expect-error
1398
1392
window . CURRENT_TOOLTIP_ELEMENT = wrapper ;
1399
- // @ts -expect-error
1400
- window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE = e ;
1401
- // @ts -expect-error
1402
1393
clearTooltipHoverTimeout ( window . CURRENT_TOOLTIP_ELEMENT ) ;
1403
1394
wrapper . onpointerenter = ev => {
1404
1395
// If this is a synthetic touch event, ignore it. A click event will be along shortly.
@@ -1433,19 +1424,15 @@ function preLoadCss(cssUrl) {
1433
1424
*/
1434
1425
function setTooltipHoverTimeout ( element , show ) {
1435
1426
clearTooltipHoverTimeout ( element ) ;
1436
- // @ts -expect-error
1437
1427
if ( ! show && ! window . CURRENT_TOOLTIP_ELEMENT ) {
1438
1428
// To "hide" an already hidden element, just cancel its timeout.
1439
1429
return ;
1440
1430
}
1441
- // @ts -expect-error
1442
1431
if ( show && window . CURRENT_TOOLTIP_ELEMENT ) {
1443
1432
// To "show" an already visible element, just cancel its timeout.
1444
1433
return ;
1445
1434
}
1446
- // @ts -expect-error
1447
1435
if ( window . CURRENT_TOOLTIP_ELEMENT &&
1448
- // @ts -expect-error
1449
1436
window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE !== element ) {
1450
1437
// Don't do anything if another tooltip is already visible.
1451
1438
return ;
@@ -1468,24 +1455,20 @@ function preLoadCss(cssUrl) {
1468
1455
*/
1469
1456
function clearTooltipHoverTimeout ( element ) {
1470
1457
if ( element . TOOLTIP_HOVER_TIMEOUT !== undefined ) {
1471
- // @ts -expect-error
1472
1458
removeClass ( window . CURRENT_TOOLTIP_ELEMENT , "fade-out" ) ;
1473
1459
clearTimeout ( element . TOOLTIP_HOVER_TIMEOUT ) ;
1474
1460
delete element . TOOLTIP_HOVER_TIMEOUT ;
1475
1461
}
1476
1462
}
1477
1463
1478
- // @ts -expect-error
1464
+ /**
1465
+ * @param {Event & { relatedTarget: Node } } event
1466
+ */
1479
1467
function tooltipBlurHandler ( event ) {
1480
- // @ts -expect-error
1481
1468
if ( window . CURRENT_TOOLTIP_ELEMENT &&
1482
- // @ts -expect-error
1483
1469
! window . CURRENT_TOOLTIP_ELEMENT . contains ( document . activeElement ) &&
1484
- // @ts -expect-error
1485
1470
! window . CURRENT_TOOLTIP_ELEMENT . contains ( event . relatedTarget ) &&
1486
- // @ts -expect-error
1487
1471
! window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . contains ( document . activeElement ) &&
1488
- // @ts -expect-error
1489
1472
! window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . contains ( event . relatedTarget )
1490
1473
) {
1491
1474
// Work around a difference in the focus behaviour between Firefox, Chrome, and Safari.
@@ -1507,30 +1490,22 @@ function preLoadCss(cssUrl) {
1507
1490
* If set to `false`, leave keyboard focus alone.
1508
1491
*/
1509
1492
function hideTooltip ( focus ) {
1510
- // @ts -expect-error
1511
1493
if ( window . CURRENT_TOOLTIP_ELEMENT ) {
1512
- // @ts -expect-error
1513
1494
if ( window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . TOOLTIP_FORCE_VISIBLE ) {
1514
1495
if ( focus ) {
1515
- // @ts -expect-error
1516
1496
window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . focus ( ) ;
1517
1497
}
1518
- // @ts -expect-error
1519
1498
window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . TOOLTIP_FORCE_VISIBLE = false ;
1520
1499
}
1521
- // @ts -expect-error
1522
1500
document . body . removeChild ( window . CURRENT_TOOLTIP_ELEMENT ) ;
1523
- // @ts -expect-error
1524
1501
clearTooltipHoverTimeout ( window . CURRENT_TOOLTIP_ELEMENT ) ;
1525
- // @ts -expect-error
1526
- window . CURRENT_TOOLTIP_ELEMENT = null ;
1502
+ window . CURRENT_TOOLTIP_ELEMENT = undefined ;
1527
1503
}
1528
1504
}
1529
1505
1530
1506
onEachLazy ( document . getElementsByClassName ( "tooltip" ) , e => {
1531
1507
e . onclick = ( ) => {
1532
1508
e . TOOLTIP_FORCE_VISIBLE = e . TOOLTIP_FORCE_VISIBLE ? false : true ;
1533
- // @ts -expect-error
1534
1509
if ( window . CURRENT_TOOLTIP_ELEMENT && ! e . TOOLTIP_FORCE_VISIBLE ) {
1535
1510
hideTooltip ( true ) ;
1536
1511
} else {
@@ -1566,9 +1541,7 @@ function preLoadCss(cssUrl) {
1566
1541
if ( ev . pointerType !== "mouse" ) {
1567
1542
return ;
1568
1543
}
1569
- // @ts -expect-error
1570
1544
if ( ! e . TOOLTIP_FORCE_VISIBLE && window . CURRENT_TOOLTIP_ELEMENT &&
1571
- // @ts -expect-error
1572
1545
! window . CURRENT_TOOLTIP_ELEMENT . contains ( ev . relatedTarget ) ) {
1573
1546
// Tooltip pointer leave gesture:
1574
1547
//
@@ -1601,7 +1574,6 @@ function preLoadCss(cssUrl) {
1601
1574
// * https://www.nngroup.com/articles/tooltip-guidelines/
1602
1575
// * https://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown
1603
1576
setTooltipHoverTimeout ( e , false ) ;
1604
- // @ts -expect-error
1605
1577
addClass ( window . CURRENT_TOOLTIP_ELEMENT , "fade-out" ) ;
1606
1578
}
1607
1579
} ;
@@ -1707,8 +1679,7 @@ function preLoadCss(cssUrl) {
1707
1679
if ( isHelpPage ) {
1708
1680
const help_section = document . createElement ( "section" ) ;
1709
1681
help_section . appendChild ( container ) ;
1710
- // @ts -expect-error
1711
- document . getElementById ( "main-content" ) . appendChild ( help_section ) ;
1682
+ nonnull ( document . getElementById ( "main-content" ) ) . appendChild ( help_section ) ;
1712
1683
} else {
1713
1684
onEachLazy ( document . getElementsByClassName ( "help-menu" ) , menu => {
1714
1685
if ( menu . offsetWidth !== 0 ) {
@@ -1854,8 +1825,7 @@ function preLoadCss(cssUrl) {
1854
1825
sidebarButton . addEventListener ( "click" , e => {
1855
1826
removeClass ( document . documentElement , "hide-sidebar" ) ;
1856
1827
updateLocalStorage ( "hide-sidebar" , "false" ) ;
1857
- if ( document . querySelector ( ".rustdoc.src" ) ) {
1858
- // @ts -expect-error
1828
+ if ( window . rustdocToggleSrcSidebar ) {
1859
1829
window . rustdocToggleSrcSidebar ( ) ;
1860
1830
}
1861
1831
e . preventDefault ( ) ;
0 commit comments