0

I'm using "amazon-connect-streams" npm package. The package has a few mismatches between the type definition and the javascript runtime.

I'm trying to override the bad typing in my project, using namespace augmentation, but can't figure out how to do it.

This is the code that fails:

import "amazon-connect-streams";

function test() {
  connect.agent(() => {}).unsubscribe(); // <-- TS2339: Property 'unsubscribe' does not exist on type 'void'.
}

It fails because agent is defined in "amazon-connect-streams" library this way:

declare namespace connect {
  type AgentCallback = (agent: Agent) => void;

  function agent(callback: AgentCallback): void;

  \\ ...
}

However, the function actually do return a value. So I tried to override the function definition, but this now fails with a different error:

import "amazon-connect-streams";

declare namespace connect {
  interface ConnectUnsubscribe {
    unsubscribe: () => void;
  }

  function agent(callback: connect.AgentCallback): ConnectUnsubscribe; // <-- TS2694: Namespace 'connect' has no exported member 'AgentCallback'.
}

function test() {
  connect.agent(() => {}).unsubscribe();
}

Is there a way to solve this error, without redefining the whole namespace?

gamliela
  • 3,447
  • 1
  • 35
  • 41
  • You should definitely open an issue about this. – kelsny Mar 09 '22 at 13:55
  • You mean, for the package maintainers? I did but the response time doesn't look good. I'm looking for an interim solution. – gamliela Mar 09 '22 at 20:19
  • Ok since this package (grossly) adds a global variable, you would need to do global augmentation. There is an article in the docs on this that you can read. – kelsny Mar 09 '22 at 22:43

0 Answers0