-
Notifications
You must be signed in to change notification settings - Fork 81
Description
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
- Install
@deepgram/sdkin a TypeScript project by runningnpm i @deepgram/sdk --production. - Import something from
@deepgram/sdkin your project. - Run
tscin 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.