Skip to content

Commit 8ca6716

Browse files
committed
rustdoc-search: address typescript nit
Co-authored-by: lolbinarycat <[email protected]
1 parent 36d10b6 commit 8ca6716

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

src/librustdoc/html/static/js/rustdoc.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,18 @@ declare namespace rustdoc {
435435
*/
436436
type RawFunctionType = number | [number, Array<RawFunctionType>] | [number, Array<RawFunctionType>, Array<[RawFunctionType, RawFunctionType[]]>];
437437

438+
/**
439+
* Utility typedef for deserializing compact JSON.
440+
*
441+
* R is the required part, O is the optional part, which goes afterward.
442+
* For example, `ArrayWithOptionals<[A, B], [C, D]>` matches
443+
* `[A, B] | [A, B, C] | [A, B, C, D]`.
444+
*/
445+
type ArrayWithOptionals<R extends any[], O extends any[]> =
446+
O extends [infer First, ...infer Rest] ?
447+
R | ArrayWithOptionals<[...R, First], Rest> :
448+
R;
449+
438450
/**
439451
* The type signature entry in the decoded search index.
440452
* (The "Raw" objects are encoded differently to save space in the JSON).

src/librustdoc/html/static/js/search.js

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,24 +1541,15 @@ class DocSearch {
15411541
* deprecated,
15421542
* isUnstable,
15431543
* associated_item_disambiguator
1544-
* @type {[
1544+
* @type {rustdoc.ArrayWithOptionals<[
15451545
* number,
15461546
* rustdoc.ItemType,
15471547
* number,
15481548
* number,
15491549
* number,
15501550
* number,
15511551
* number,
1552-
* string,
1553-
* ] | [
1554-
* number,
1555-
* rustdoc.ItemType,
1556-
* number,
1557-
* number,
1558-
* number,
1559-
* number,
1560-
* number,
1561-
* ]}
1552+
* ], [string]>}
15621553
*/
15631554
const raw = JSON.parse(encoded);
15641555
return {
@@ -1587,26 +1578,8 @@ class DocSearch {
15871578
return null;
15881579
}
15891580
/**
1590-
* ty, module_path, exact_module_path, search_unbox, inverted_function_signature_index
1591-
* @type {[
1592-
* rustdoc.ItemType,
1593-
* string,
1594-
* string|0,
1595-
* 0|1,
1596-
* string,
1597-
* ] | [
1598-
* rustdoc.ItemType,
1599-
* string,
1600-
* string|0,
1601-
* 0|1,
1602-
* ] | [
1603-
* rustdoc.ItemType,
1604-
* string,
1605-
* string,
1606-
* ] | [
1607-
* rustdoc.ItemType,
1608-
* string,
1609-
* ]}
1581+
* ty, module_path, exact_module_path, search_unbox, inverted_function_signature_index
1582+
* @type {rustdoc.ArrayWithOptionals<[rustdoc.ItemType, string], [string|0, 0|1, string]>}
16101583
*/
16111584
const raw = JSON.parse(encoded);
16121585
return {

0 commit comments

Comments
 (0)