Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@types/ws should be in dependencies of package.json rather than in devDependencies because those types are publicly exposed #355

Open
ibc opened this issue Jan 14, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@ibc
Copy link

ibc commented Jan 14, 2025

What is the current behavior?

Installing @deepgram/sdk in a TypeScript environment in production mode fails due to missing ws types.

This is because here it imports types from ws dependency:

import type { WebSocket as WSWebSocket } from "ws";

Such an import is later present in dist/module/packages/AbstractLiveClient.d.ts which is part of the published code in the NPM registry.

And then the AbstractLiveClient code uses it as follows:

type WebSocketLike = WebSocket | WSWebSocket | WSWebSocketDummy;
export abstract class AbstractLiveClient extends AbstractClient {
  public headers: { [key: string]: string };
  public transport: WebSocketLikeConstructor | null;
  public conn: WebSocketLike | null = null;
  public sendBuffer: Function[] = [];

That's the problem: The publicly exposed AbstractLiveClient has a public member conn whose type is WebSocketLike which is a type that depends on a type from the ws package. So in summary @deepgram/sdk is directly exposing a type from ws and hence ws types must also be included in dependencies of @deepgram/sdk rather than in devDependencies (which are not installed in production mode).

Steps to reproduce

  1. Install @deepgram/sdk in a TypeScript project by running npm i @deepgram/sdk --production.
  2. Import something from @deepgram/sdk in your project.
  3. Run tsc in your project.

Expected behavior

TypeScript doesn't complain.

Real behavior

TypeScript complains because couldn't find a declaration file for module 'ws'.

Solution

Move @types/ws from devDependencies to dependencies in package.json.

@lukeocodes lukeocodes added the bug Something isn't working label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants