TypeScript: Unable to augment exported function from a module with a overload signature

TypeScript Version: 2.7.1

Search Terms: augment module function export

Code

// imports.ts
export function test(arg: number): any;
export function test(arg: number): any {
  return arg.toString();
}

// augmentations.ts
import { test } from './imports';

declare module './imports' {
  function test(arg: string): any; //  TS2384: Overload signatures must all be ambient or non-ambient.
}

test('foo');

Expected behavior: test function from imports.ts is augmented with overloaded string signature.

Actual behavior: TS2384 Error

I tried to hunt down this issue as I thought it previously existed but after numerous pages of other unrelated issues I gave up the hunt. I believe this issue has been around since the beginning of module augmentations, and perhaps it is by design. I suspect the problem is that there is no way to define a static module function as a module augmentation.

I have run into use cases where this ability would be very useful. Typically when a particular library lags behind in updating their type declarations, but deficiencies in the typings are not declared within a class or interface scope. The solution is typically to just hold back on updating typescript, until the library is properly updated (which can sometimes be long wait depending on how active the library is).

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (6 by maintainers)

Most upvoted comments

there will be a separate pull request for the ix module, their typings are incorrect and need to be patched. This issue is to address the inability to augment static function exports from a module.