Skip to content

Unable to augment exported function from a module with a overload signature #21566

@patsissons

Description

@patsissons

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExternalRelates to another program, environment, or user action which we cannot control.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions