# @types/koa-websocket

> TypeScript definitions for koa-websocket

Latest version **5.0.11** (published 2025-10-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @types/koa-websocket
pnpm add @types/koa-websocket
yarn add @types/koa-websocket
bun add @types/koa-websocket
```

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; no vulnerabilities; high maintenance score; popular repo; extremely popular.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 5.0.11 |
| Published | 2025-10-24 |
| First published | 2017-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 51439 |
| Maintainers | types |

## Links

- npm: https://www.npmjs.com/package/@types/koa-websocket
- Repository: https://github.com/DefinitelyTyped/DefinitelyTyped
- Homepage: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/koa-websocket
- npm.io page: https://npm.io/package/@types/koa-websocket

## Dependencies (3)

- [@types/ws](https://npm.io/package/@types/ws.md) *
- [@types/koa](https://npm.io/package/@types/koa.md) *
- [@types/koa-compose](https://npm.io/package/@types/koa-compose.md) *

## Recent versions

- 5.0.11 (latest) — 2025-10-24
- 5.0.10 (ts5.1) — 2023-11-07
- 5.0.7 (ts4.1) — 2021-08-23
- 5.0.6 (ts3.6) — 2021-07-08
- 5.0.5 (ts3.5) — 2020-11-16
- 5.0.4 (ts2.4) — 2019-06-28
- 2.1.0 (ts2.2) — 2017-05-01
- 5.0.9 — 2023-10-18
- 5.0.8 — 2023-09-14
- 5.0.3 — 2018-10-17
- 5.0.2 — 2018-07-21
- 5.0.1 — 2018-07-02
- 5.0.0 — 2018-06-21
- 2.1.2 — 2018-02-05
- 2.1.1 — 2017-11-09

## README

# Installation
> `npm install --save @types/koa-websocket`

# Summary
This package contains type definitions for koa-websocket (https://github.com/kudos/koa-websocket).

# Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/koa-websocket.
## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/koa-websocket/index.d.ts)
````ts
import Koa = require("koa");
import compose = require("koa-compose");
import * as http from "http";
import * as https from "https";
import ws = require("ws");

declare module "koa" {
    interface Context {
        websocket: ws;
        path: string;
    }
}

declare namespace KoaWebsocket {
    type Middleware<StateT = Koa.DefaultState, ContextT = Koa.DefaultContext> = compose.Middleware<
        MiddlewareContext<StateT> & ContextT
    >;

    interface MiddlewareContext<StateT> extends Koa.Context {
        // Limitation: Declaration merging cannot overwrap existing properties.
        // That's why this property is here, not in the merged declaration above.
        app: App;
        state: StateT;
    }

    class Server<StateT = Koa.DefaultState, ContextT = Koa.DefaultContext> {
        app: App;
        middleware: Array<Middleware<StateT, ContextT>>;
        server?: ws.Server | undefined;

        constructor(app: Koa<StateT, ContextT>);

        listen(options: ws.ServerOptions): ws.Server;
        onConnection(socket: ws, request: http.IncomingMessage): void;
        use(middleware: Middleware<StateT, ContextT>): this;
    }

    interface App<StateT = Koa.DefaultState, ContextT = Koa.DefaultContext> extends Koa<StateT, ContextT> {
        ws: Server<StateT, ContextT>;
    }
}

declare function KoaWebsocket<
    StateT = Koa.DefaultState,
    ContextT = Koa.DefaultContext,
>(
    app: Koa<StateT, ContextT>,
    wsOptions?: ws.ServerOptions,
    httpsOptions?: https.ServerOptions,
): KoaWebsocket.App<StateT, ContextT>;

export = KoaWebsocket;

````

### Additional Details
 * Last updated: Fri, 24 Oct 2025 04:02:41 GMT
 * Dependencies: [@types/koa](https://npmjs.com/package/@types/koa), [@types/koa-compose](https://npmjs.com/package/@types/koa-compose), [@types/ws](https://npmjs.com/package/@types/ws)

# Credits
These definitions were written by [Maël Lavault](https://github.com/moimael), [Jaco Greeff](https://github.com/jacogr), [Martin Ždila](https://github.com/zdila), [Eunchong Yu](https://github.com/Kroisse), [Christopher N. Katoyi-Kaba](https://github.com/Christopher2K), and [Zuo Jiazi](https://github.com/Aoiujz).

---
_Source: https://npm.io/package/@types/koa-websocket · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
