# 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).
