<!-- thumbnail: https://example.com/some-image.png --> <!-- version: 2.4.1 --> <!-- tag: library --> <!-- excerpt: Stack Exchange global types adds or augments type definitions for global objects exposed by Stack Exchange to aid userscript authors --> ## Screenshot / Code Snippet [![animated usage example][1]][1] ## About Stack Exchange global types is a type declaration package adding or augmenting type definitions for global objects exposed by Stack Exchange for client-side consumption on pages of network sites. Currently, the package includes the `StackExchange`, `StackOverflow`, `CHAT`, `Svg`, and `Stacks` global object definitions. ## Change log Please note that the major version 2 starts from the patch version 2.0.2 due to the technical difficulties we encountered when bumping the major version. | Since | Feature | Definitions/augmentations | Known Limitations | | - | - | - | - | | 1.0.0 | augments `Stacks` exposed by the [@stackoverflow/stacks][2] package | Adds missing classes and helper methods like `showModal`/`hideModal` (see [example usage][3] in official Stacks docs) | | | 1.1.0 | adds type definitions for `StackExchange` object (exposed on all pages on the network sites) | Full definition (for example, `StackExchange.options.user.isRegistered`) - as most of the Stack Exchange codebase is not open-source, so there are no type definitions available to augment | v1.1.1 only includes some of the exposed helper methods as each needs to be tested | | 1.2.0 | adds type definitions for the `CHAT` object | Full definition (for example, `CHAT.user.canModerate()`) | | 1.2.1 | adds `question` nested object to `StackExchange` global object | Three new method definitions:<br>`getQuestionId()`, `canViewVoteCounts()`, `scrollToPost(postId)` | `getQuestionId` throws an error on non-post pages, but that's not expressable via declarations | | 1.2.2 | type docs & improvements | Courtesy of [double-beep][4]: documentation for types and stricter `AllPlacements` | | [1.3.0][5] | adds `settings` object for `StackExchange` object | Partial definition - adds account, flagging, markdown, and site-wide settings definitions | | | [1.4.0][6] | more type definitions for the `CHAT` global object courtesy of [double-beep][4] | Full definition for `UserInformation`, `RoomUsersInfo`, and several methods | | [1.5.0][7] | methods on `StackExchange` global object | adds `ready` and `gaReady` defer methods | | [2.0.2][8] | `Stacks` namespace declaration merging; package splitting | Merges `Stacks` declaration with official TypeScript source; splits the declarations into 3 submodules: `chat`, `stackexchange`, and `stacks` (can be imported directly as `@userscripters/stackexchange-global-types/lib/<module>` if you only need some of the global types or as a bundle if you import the package with `@userscripters/stackexchange-global-types`) | | [2.1.0][9] | adds type definitions for the `Svg` object | Full definition of all 228 icon helpers courtesy of [double-beep][4] | | | [2.1.1][10] | improved `Stacks` definitions | `ModalController` defintion & tests | | [2.2.0][11] | new testing framework | switched to [tsd][12] for testing - please upgrade if you see a "Patch file found for package definitelytyped-header-parser" error when installing the package | | [2.3.0][13] | adds type definitions for the `StackOverflow` object | Full definition of all enums | | [2.4.0][23] | adds `realtime` property and corresponding `Realtime` interface on the global `StackExchange` object | Full definition of all properties and methods | | [2.4.1][24] | adds Stimulus `application` singleton and controller utilities to the `Stacks` namespace | Courtesy of [Martijn Pieters][25]: `ControllerDefinition` interface, `createController` and `addController` utilities, `application` singleton | ### License The script is licensed under the [GPL-3.0-or-later][14] license. ### Download The package is published as both an [NPM package][15] and a [GitHub package][16]. Can be installed via a package manager like NPM as usual: ```shell npm install --save-dev @userscripters/stackexchange-global-types ``` If you opt to install it from the GitHub registry, please note that it only supports scoped packages, you will need a simple .npmrc file at your project root: ```npmrc @userscripters:registry=https://npm.pkg.github.com ``` You will also need to be logged in to GitHub. An easy way to do so is to have a global `.npmrc` with your PAT ([personal access token][14]) set as an access token: ```npmrc //npm.pkg.github.com/:_authToken=<your token here> ``` ### Platform The type declarations are intended to be used with TypeScript/JavaScript projects targeting browsers. ## Contact Author: [Oleg Valter][17]<br> Organization: [UserScripters][18] Contributors (core):<br> [double-beep][4] (with special thanks for initial definitions and docs) Contributors:<br> [Martijn Pieters][25] Please, submit bug reports on the [source repository][19]. Before adding a new one, please check if it hasn't been raised before. You can also [drop by to chat][20], we are a friendly bunch. ## Code [Source code][21] is written TypeScript (`d.ts` declaration files). The project is using `tsd` (see [repo][12]) for unit-testing types. Contributions are welcome, you can always submit a [PR here][22]. [1]: https://i.sstatic.net/v21na.gif [2]: https://www.npmjs.com/package/@stackoverflow/stacks [3]: https://stackoverflow.design/product/components/modals/#helpers [4]: https://stackoverflow.com/users/10607772/double-beep [5]: https://github.com/userscripters/stackexchange-global-types/releases/tag/v1.3.0 [6]: https://github.com/userscripters/stackexchange-global-types/releases/tag/v1.4.0 [7]: https://github.com/userscripters/stackexchange-global-types/releases/tag/v1.5.0 [8]: https://github.com/userscripters/stackexchange-global-types/releases/tag/v2.0.2 [9]: https://github.com/userscripters/stackexchange-global-types/releases/tag/v2.1.0 [10]: https://github.com/userscripters/stackexchange-global-types/releases/tag/v2.1.1 [11]: https://github.com/userscripters/stackexchange-global-types/releases/tag/v2.2.0 [12]: https://www.npmjs.com/package/tsd [13]: https://github.com/userscripters/stackexchange-global-types/releases/tag/v2.3.0 [14]: https://spdx.org/licenses/GPL-3.0-or-later [15]: https://www.npmjs.com/package/@userscripters/stackexchange-global-types [16]: https://github.com/userscripters/stackexchange-global-types/packages/922352 [17]: https://stackoverflow.com/users/11407695/oleg-valter [18]: https://github.com/userscripters [19]: https://github.com/userscripters/stackexchange-global-types/issues [20]: https://chat.stackoverflow.com/rooms/214345/userscript-newbies-and-friends [21]: https://github.com/userscripters/stackexchange-global-types/blob/master/index.d.ts [22]: https://github.com/userscripters/stackexchange-global-types/pulls [23]: https://github.com/userscripters/stackexchange-global-types/releases/tag/v2.4.0 [24]: https://github.com/userscripters/stackexchange-global-types/releases/tag/v2.4.1 [25]: https://stackoverflow.com/users/100297/martijn-pieters