Skip to content

Global export type conflict with Recurly node client #139

Open
@rishibajekal

Description

@rishibajekal

Overview

I have a monolith project that relies on both the Recurly node client as well as React-Recurly.

The Recurly node client exports a global namespace in its types file (node_modules/recurly/lib/recurly.d.ts):

export as namespace recurly;

React Recurly depends on recurly.js types (node_modules/@types/recurly__recurly-js/index.d.ts), which exports a global recurly:

declare global {
  interface Window {
    recurly: Recurly;
  }
  const recurly: Recurly;
}

The issue I'm encountering is that the global defined by the node client is clashing with that of the recurly.js types file.

Error

node_modules/@types/recurly__recurly-js/index.d.ts:14:9 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'recurly' must be of type 'typeof import("node_modules/recurly/lib/recurly")', but here has type 'Recurly'.
14   const recurly: Recurly;
           ~~~~~~~
  node_modules/recurly/lib/recurly.d.ts:5:1
    5 export as namespace recurly;
      ~~~~~~
    'recurly' was also declared here.

TypeScript limitation

There is a known limitation in TypeScript that global type definitions can only be included but not excluded, which makes it quite difficult to get around this issue for projects that encounter it. I have tried within my project to follow the suggested workaround but I'm still unable to avoid the error above.

Questions

  1. I imagine using both these packages within the same project is a fairly common scenario. Are there any known workarounds?
  2. Can the next version of one or both of the packages rename the global exports to avoid this conflict?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions