Skip to content

Commit 6c82958

Browse files
committed
fix signature of onEachLazy and onEach to remove some errors
1 parent 854f225 commit 6c82958

File tree

3 files changed

+13
-25
lines changed

3 files changed

+13
-25
lines changed

src/librustdoc/html/static/js/main.js

+4-21
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ const ALTERNATIVE_DISPLAY_ID = "alternative-display";
103103
const NOT_DISPLAYED_ID = "not-displayed";
104104
const HELP_BUTTON_ID = "help-button";
105105

106+
/**
107+
* @returns {HTMLElement}
108+
*/
106109
function getSettingsButton() {
110+
// @ts-expect-error
107111
return document.getElementById(SETTINGS_BUTTON_ID);
108112
}
109113

@@ -236,7 +240,6 @@ function preLoadCss(cssUrl) {
236240
}
237241

238242
if (getSettingsButton()) {
239-
// @ts-expect-error
240243
getSettingsButton().onclick = event => {
241244
if (event.ctrlKey || event.altKey || event.metaKey) {
242245
return;
@@ -470,7 +473,6 @@ function preLoadCss(cssUrl) {
470473
}
471474
return onEachLazy(implElem.parentElement.parentElement.querySelectorAll(
472475
`[id^="${assocId}"]`),
473-
// @ts-expect-error
474476
item => {
475477
const numbered = /^(.+?)-([0-9]+)$/.exec(item.id);
476478
if (item.id === assocId || (numbered && numbered[1] === assocId)) {
@@ -687,7 +689,6 @@ function preLoadCss(cssUrl) {
687689
//
688690
// By the way, this is only used by and useful for traits implemented automatically
689691
// (like "Send" and "Sync").
690-
// @ts-expect-error
691692
onEachLazy(synthetic_implementors.getElementsByClassName("impl"), el => {
692693
const aliases = el.getAttribute("data-aliases");
693694
if (!aliases) {
@@ -740,7 +741,6 @@ function preLoadCss(cssUrl) {
740741
code.innerHTML = struct[TEXT_IDX];
741742
addClass(code, "code-header");
742743

743-
// @ts-expect-error
744744
onEachLazy(code.getElementsByTagName("a"), elem => {
745745
const href = elem.getAttribute("href");
746746

@@ -886,15 +886,13 @@ function preLoadCss(cssUrl) {
886886
const template = document.createElement("template");
887887
template.innerHTML = text;
888888

889-
// @ts-expect-error
890889
onEachLazy(template.content.querySelectorAll("a"), elem => {
891890
const href = elem.getAttribute("href");
892891

893892
if (href && !href.startsWith("#") && !/^(?:[a-z+]+:)?\/\//.test(href)) {
894893
elem.setAttribute("href", window.rootPath + href);
895894
}
896895
});
897-
// @ts-expect-error
898896
onEachLazy(template.content.querySelectorAll("[id]"), el => {
899897
let i = 0;
900898
if (idMap.has(el.id)) {
@@ -912,7 +910,6 @@ function preLoadCss(cssUrl) {
912910
const oldHref = `#${el.id}`;
913911
const newHref = `#${el.id}-${i}`;
914912
el.id = `${el.id}-${i}`;
915-
// @ts-expect-error
916913
onEachLazy(template.content.querySelectorAll("a[href]"), link => {
917914
if (link.getAttribute("href") === oldHref) {
918915
link.href = newHref;
@@ -933,7 +930,6 @@ function preLoadCss(cssUrl) {
933930
// @ts-expect-error
934931
sidebarTraitList.append(li);
935932
} else {
936-
// @ts-expect-error
937933
onEachLazy(templateAssocItems, item => {
938934
let block = hasClass(item, "associatedtype") ? associatedTypes : (
939935
hasClass(item, "associatedconstant") ? associatedConstants : (
@@ -1040,7 +1036,6 @@ function preLoadCss(cssUrl) {
10401036
function expandAllDocs() {
10411037
const innerToggle = document.getElementById(toggleAllDocsId);
10421038
removeClass(innerToggle, "will-expand");
1043-
// @ts-expect-error
10441039
onEachLazy(document.getElementsByClassName("toggle"), e => {
10451040
if (!hasClass(e, "type-contents-toggle") && !hasClass(e, "more-examples-toggle")) {
10461041
e.open = true;
@@ -1053,7 +1048,6 @@ function preLoadCss(cssUrl) {
10531048
function collapseAllDocs() {
10541049
const innerToggle = document.getElementById(toggleAllDocsId);
10551050
addClass(innerToggle, "will-expand");
1056-
// @ts-expect-error
10571051
onEachLazy(document.getElementsByClassName("toggle"), e => {
10581052
if (e.parentNode.id !== "implementations-list" ||
10591053
(!hasClass(e, "implementors-toggle") &&
@@ -1092,7 +1086,6 @@ function preLoadCss(cssUrl) {
10921086
function setImplementorsTogglesOpen(id, open) {
10931087
const list = document.getElementById(id);
10941088
if (list !== null) {
1095-
// @ts-expect-error
10961089
onEachLazy(list.getElementsByClassName("implementors-toggle"), e => {
10971090
e.open = open;
10981091
});
@@ -1104,7 +1097,6 @@ function preLoadCss(cssUrl) {
11041097
setImplementorsTogglesOpen("blanket-implementations-list", false);
11051098
}
11061099

1107-
// @ts-expect-error
11081100
onEachLazy(document.getElementsByClassName("toggle"), e => {
11091101
if (!hideLargeItemContents && hasClass(e, "type-contents-toggle")) {
11101102
e.open = true;
@@ -1124,7 +1116,6 @@ function preLoadCss(cssUrl) {
11241116
}
11251117
onEachLazy(document.querySelectorAll(
11261118
":not(.scraped-example) > .example-wrap > pre:not(.example-line-numbers)",
1127-
// @ts-expect-error
11281119
), x => {
11291120
const parent = x.parentNode;
11301121
const line_numbers = parent.querySelectorAll(".example-line-numbers");
@@ -1145,7 +1136,6 @@ function preLoadCss(cssUrl) {
11451136

11461137
// @ts-expect-error
11471138
window.rustdoc_remove_line_numbers_from_examples = () => {
1148-
// @ts-expect-error
11491139
onEachLazy(document.querySelectorAll(".example-wrap > .example-line-numbers"), x => {
11501140
x.parentNode.removeChild(x);
11511141
});
@@ -1193,7 +1183,6 @@ function preLoadCss(cssUrl) {
11931183
mainElem.addEventListener("click", hideSidebar);
11941184
}
11951185

1196-
// @ts-expect-error
11971186
onEachLazy(document.querySelectorAll("a[href^='#']"), el => {
11981187
// For clicks on internal links (<A> tags with a hash property), we expand the section we're
11991188
// jumping to *before* jumping there. We can't do this in onHashChange, because it changes
@@ -1204,7 +1193,6 @@ function preLoadCss(cssUrl) {
12041193
});
12051194
});
12061195

1207-
// @ts-expect-error
12081196
onEachLazy(document.querySelectorAll(".toggle > summary:not(.hideme)"), el => {
12091197
// @ts-expect-error
12101198
el.addEventListener("click", e => {
@@ -1422,7 +1410,6 @@ function preLoadCss(cssUrl) {
14221410
}
14231411
}
14241412

1425-
// @ts-expect-error
14261413
onEachLazy(document.getElementsByClassName("tooltip"), e => {
14271414
e.onclick = () => {
14281415
e.TOOLTIP_FORCE_VISIBLE = e.TOOLTIP_FORCE_VISIBLE ? false : true;
@@ -1522,9 +1509,7 @@ function preLoadCss(cssUrl) {
15221509
if (!getHelpButton().contains(document.activeElement) &&
15231510
// @ts-expect-error
15241511
!getHelpButton().contains(event.relatedTarget) &&
1525-
// @ts-expect-error
15261512
!getSettingsButton().contains(document.activeElement) &&
1527-
// @ts-expect-error
15281513
!getSettingsButton().contains(event.relatedTarget)
15291514
) {
15301515
// @ts-expect-error
@@ -1639,7 +1624,6 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
16391624
*/
16401625
// @ts-expect-error
16411626
window.hidePopoverMenus = () => {
1642-
// @ts-expect-error
16431627
onEachLazy(document.querySelectorAll("rustdoc-toolbar .popover"), elem => {
16441628
elem.style.display = "none";
16451629
});
@@ -2159,7 +2143,6 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
21592143
buttons.classList.toggle("keep-visible");
21602144
}
21612145

2162-
// @ts-expect-error
21632146
onEachLazy(document.querySelectorAll(".docblock .example-wrap"), elem => {
21642147
elem.addEventListener("mouseover", addCopyButton);
21652148
elem.addEventListener("click", showHideCodeExampleButtons);

src/librustdoc/html/static/js/settings.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
(function() {
1212
const isSettingsPage = window.location.pathname.endsWith("/settings.html");
1313

14+
/**
15+
* @param {string} settingName
16+
* @param {bool} value
17+
*/
1418
function changeSetting(settingName, value) {
1519
if (settingName === "theme") {
1620
const useSystem = value === "system preference" ? "true" : "false";
@@ -171,7 +175,7 @@
171175
/**
172176
* This function builds the "settings page" and returns the generated HTML element.
173177
*
174-
* @return {HTMLElement}
178+
* @returns {HTMLElement}
175179
*/
176180
function buildSettingsPage() {
177181
const theme_names = getVar("themes").split(",").filter(t => t);
@@ -293,7 +297,8 @@
293297
if (!isSettingsPage) {
294298
// We replace the existing "onclick" callback.
295299
const settingsButton = getSettingsButton();
296-
const settingsMenu = document.getElementById("settings");
300+
// tell typescript this can never be null
301+
const settingsMenu = /** @type {HTMLElement} */ (document.getElementById("settings"));
297302
settingsButton.onclick = event => {
298303
if (settingsMenu.contains(event.target)) {
299304
return;

src/librustdoc/html/static/js/storage.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function removeClass(elem, className) {
8585
/**
8686
* Run a callback for every element of an Array.
8787
* @param {Array<?>} arr - The array to iterate over
88-
* @param {function(?): boolean|undefined} func - The callback
88+
* @param {function(?): boolean|void} func - The callback
8989
*/
9090
function onEach(arr, func) {
9191
for (const elem of arr) {
@@ -103,7 +103,7 @@ function onEach(arr, func) {
103103
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection
104104
* https://developer.mozilla.org/en-US/docs/Web/API/NodeList
105105
* @param {NodeList|HTMLCollection} lazyArray - An array to iterate over
106-
* @param {function(?): boolean} func - The callback
106+
* @param {function(?): boolean|void} func - The callback
107107
*/
108108
// eslint-disable-next-line no-unused-vars
109109
function onEachLazy(lazyArray, func) {

0 commit comments

Comments
 (0)