fastify / fastify/fastify-websocket

`@types/ws` is missing which results in loosing typing withing handler

Open
#300 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
468
Forks
84
PR merge metrics
No merged PRs in 30d

Description

### Prerequisites

- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported

### Fastify version

4.27.0

### Plugin version

10.0.1

### Node.js version

20.12.2

### Operating system

Windows

### Operating system version (i.e. 20.04, 11.3, 10)

10

### Description

When using this plugin with TypeScript the socket within the handler isn't typed correctly because it reexports `WebSocket.WebSocket` from `ws` which isn't listed as a dependency.

```
app.get('/new-status-route', {websocket: true}, async (socket, req) => {
// socket is any instead of WebSocket.WebSocket
```

Therefore it's necessary to install it additionally.

I think the typical solution would be listing it in `dependencies` rathern than `devDependencies`.

### Link to code that reproduces the bug

_No response_

### Expected Behavior

The plugin also installs `@types/ws` which leads to the correct type of `socket` within the handler.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.