Skip to main content
7 of 21
bumped to v1.4.0
0Valt
  • 1.4k
  • 4
  • 16

Stack Exchange Global Types - a type declaration package for global objects exposed by Stack Exchange

Screenshot / Code Snippet

animated usage example

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 following:

Since Feature Definitions/augmentations Known Limitations
1.0.0 augments Stacks exposed by the @stackoverflow/stacks package Adds missing classes and helper methods like showModal/hideModal (see example usage 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 CHAT global object Full definition (for example, CHAT.user.canModerate())
1.2.1 adds question nested object to StackExchange global object Three new method definitions:
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: documentation for types and stricter AllPlacements
1.3.0 adds settings object for StackExchange object Partial definition - adds account, flagging, markdown, and site-wide settings definitions
1.4.0 more type definitions for the CHAT global object courtesy of double-beep Full definition for UserInformation, RoomUsersInfo, and several methods

License

The script is licensed under the GPL-3.0-or-later license.

Download

The package is published as both an NPM package and a GitHub package. Can be installed via a package manager like NPM as usual:

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:

@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) set as an access token:

//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
Organization: UserScripters

Contributors (core):
double-beep (with special thanks for initial definitions and docs)

Please, submit bug reports on the source repository. Before adding a new one, please check if it hasn't been raised before.

You can also drop by to chat, we are a friendly bunch.

Code

Source code is written TypeScript (d.ts declaration files).

The project is using dtslint (see repo) for unit-testing types.

Contributions are welcome, you can always submit a PR here.

0Valt
  • 1.4k
  • 4
  • 16