Skip to content

Commit 3b259ad

Browse files
committed
rustdoc js: several typechecking improvments
non-exhaustive list of changes: * rustdoc.Results has a max_dist field * improve typechecking around pathDist and addIntoResults * give handleNameSearch a type signature * typecheck sortQ * currentCrate is string and not optional * searchState is referenced as a global, not through window
1 parent 42245d3 commit 3b259ad

File tree

2 files changed

+43
-77
lines changed

2 files changed

+43
-77
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
/* eslint-disable */
66
declare global {
7+
/** Search engine data used by main.js and search.js */
8+
declare var searchState: rustdoc.SearchState;
79
/** Defined and documented in `storage.js` */
810
declare function nonnull(x: T|null, msg: string|undefined);
911
/** Defined and documented in `storage.js` */
@@ -17,8 +19,6 @@ declare global {
1719
RUSTDOC_TOOLTIP_HOVER_MS: number;
1820
/** Used by the popover tooltip code. */
1921
RUSTDOC_TOOLTIP_HOVER_EXIT_MS: number;
20-
/** Search engine data used by main.js and search.js */
21-
searchState: rustdoc.SearchState;
2222
/** Global option, with a long list of "../"'s */
2323
rootPath: string|null;
2424
/**
@@ -102,20 +102,22 @@ declare namespace rustdoc {
102102
currentTab: number;
103103
focusedByTab: [number|null, number|null, number|null];
104104
clearInputTimeout: function;
105-
outputElement: function(): HTMLElement|null;
106-
focus: function();
107-
defocus: function();
108-
showResults: function(HTMLElement|null|undefined);
109-
removeQueryParameters: function();
110-
hideResults: function();
111-
getQueryStringParams: function(): Object.<any, string>;
105+
outputElement(): HTMLElement|null;
106+
focus();
107+
defocus();
108+
// note: an optional param is not the same as
109+
// a nullable/undef-able param.
110+
showResults(elem?: HTMLElement|null);
111+
removeQueryParameters();
112+
hideResults();
113+
getQueryStringParams(): Object.<any, string>;
112114
origPlaceholder: string;
113115
setup: function();
114-
setLoadingSearch: function();
116+
setLoadingSearch();
115117
descShards: Map<string, SearchDescShard[]>;
116118
loadDesc: function({descShard: SearchDescShard, descIndex: number}): Promise<string|null>;
117-
loadedDescShard: function(string, number, string);
118-
isDisplayed: function(): boolean,
119+
loadedDescShard(string, number, string);
120+
isDisplayed(): boolean,
119121
}
120122

121123
interface SearchDescShard {
@@ -237,7 +239,7 @@ declare namespace rustdoc {
237239
query: ParsedQuery,
238240
}
239241

240-
type Results = Map<String, ResultObject>;
242+
type Results = { max_dist?: number } & Map<number, ResultObject>
241243

242244
/**
243245
* An annotated `Row`, used in the viewmodel.

0 commit comments

Comments
 (0)