Skip to content

TypeScript Type Resolution Errors for websocketClient and restClient #250

@mgambella

Description

@mgambella

TypeScript Type Resolution Errors for websocketClient and restClient

Description

TypeScript cannot properly resolve types for websocketClient and restClient exports from @massive.com/client-js, causing them to be treated as error types. This results in unsafe assignment and call errors when using strict TypeScript/ESLint rules.

Package Version

  • @massive.com/client-js: ^9.0.0
  • TypeScript: ^5.9.3
  • ESLint with @typescript-eslint/eslint-plugin: ^8.47.0

Error Messages

For websocketClient:

Unsafe assignment of an error typed value.
Unsafe call of a(n) `error` type typed value.
Unsafe member access .stocks on an `error` typed value.

For restClient:

Unsafe assignment of an error typed value.
Unsafe call of a(n) `error` type typed value.
Unsafe member access .getStocksSnapshotTicker on an `error` typed value.

Minimal Reproduction

import { websocketClient, restClient } from '@massive.com/client-js';

// This causes type errors
const wsClient = websocketClient('api-key', 'ws-url');
const ws = wsClient.stocks(); // Error: Unsafe member access

const rest = restClient('api-key');
const snapshot = await rest.getStocksSnapshotTicker('AAPL'); // Error: Unsafe call

Expected Behavior

TypeScript should be able to properly infer and resolve the types for both websocketClient and restClient without requiring manual type assertions. The type definitions should be properly exported and accessible.

Type Definitions Location

The type definitions exist in:

  • node_modules/@massive.com/client-js/dist/main.d.ts

The declarations are:

  • declare const websocketClient: (apiKey: string, apiBase?: string, exchange?: string) => IWebsocketClient;
  • declare const restClient: (apikey: string, restApiBase?: string, globalFetchOptions?: {...}) => DefaultApi;

However, TypeScript cannot resolve these types when importing from the package.

Possible Causes

  1. Missing or incorrect types field in package.json
  2. Type definitions not properly exported from the package entry point
  3. Module resolution issues with the type definitions
  4. Missing dependencies for type resolution (e.g., websocket types)

Additional Context

  • Node.js version: >=22.18.0
  • Module system: ES modules ("type": "module")
  • The types exist in the package but TypeScript cannot resolve them during import

Suggested Fix

  1. Ensure package.json includes proper types field pointing to the type definitions
  2. Verify that all type dependencies are properly declared
  3. Consider re-exporting types explicitly if needed
  4. Test type resolution with a fresh TypeScript project

Note: This issue prevents proper type checking and IntelliSense support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions