|
18 | 18 | * @param {boolean} isHidden
|
19 | 19 | */
|
20 | 20 | function scrollToLoc(elt, loc, isHidden) {
|
| 21 | + /** @type {HTMLElement[]} */ |
| 22 | + // blocked on https://github.com/microsoft/TypeScript/issues/29037 |
| 23 | + // @ts-expect-error |
21 | 24 | const lines = elt.querySelectorAll("[data-nosnippet]");
|
22 | 25 | let scrollOffset;
|
23 | 26 |
|
|
57 | 60 | window.updateScrapedExample = (example, buttonHolder) => {
|
58 | 61 | let locIndex = 0;
|
59 | 62 | const highlights = Array.prototype.slice.call(example.querySelectorAll(".highlight"));
|
| 63 | + |
| 64 | + /** @type {HTMLAnchorElement} */ |
60 | 65 | const link = nonnull(example.querySelector(".scraped-example-title a"));
|
61 | 66 | let expandButton = null;
|
62 | 67 |
|
|
72 | 77 | const prev = createScrapeButton(buttonHolder, "prev", "Previous usage");
|
73 | 78 |
|
74 | 79 | // Toggle through list of examples in a given file
|
| 80 | + /** @type {function(function(): void): void} */ |
75 | 81 | const onChangeLoc = changeIndex => {
|
76 | 82 | removeClass(highlights[locIndex], "focus");
|
77 | 83 | changeIndex();
|
|
117 | 123 | /**
|
118 | 124 | * Intitialize the `locs` field
|
119 | 125 | *
|
120 |
| - * @param {HTMLElement} example |
| 126 | + * @param {HTMLElement & {locs?: rustdoc.ScrapedLoc[]}} example |
121 | 127 | * @param {boolean} isHidden
|
122 | 128 | */
|
123 | 129 | function setupLoc(example, isHidden) {
|
124 |
| - // @ts-expect-error |
125 |
| - example.locs = JSON.parse(example.attributes.getNamedItem("data-locs").textContent); |
| 130 | + const locs = example.locs = JSON.parse(nonnull(nonnull(example.attributes.getNamedItem("data-locs")).textContent)); |
126 | 131 | // Start with the first example in view
|
127 |
| - scrollToLoc(example, example.locs[0][0], isHidden); |
| 132 | + scrollToLoc(example, locs[0][0], isHidden); |
128 | 133 | }
|
129 | 134 |
|
130 | 135 | const firstExamples = document.querySelectorAll(".scraped-example-list > .scraped-example");
|
|
0 commit comments