Skip to content

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

@ibc

Description

@ibc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions