Skip to content

Unable to overload arrow function in module augmentation #39622

Closed
@dotansimha

Description

@dotansimha

I'm trying to overload an existing arrow function in a module, exported as const. It works perfectly fine with overrides for function, class and interface, but failing for arrow function declared as const.

Also tried with:

    export interface myVar {
        (param: number): number
    }

It works, but then the arrow function become unusable because it treats it as interface and it's not callable.

TypeScript Version: 3.9.2

Search Terms: const, module augmentation, declaration merging, overload, block-scope variable

Expected behavior:

Allow to override block-scoped variables if it's referring to an arrow function. Just like a function.

Actual behavior:

Cannot redeclare block-scoped variable 'myVar'.(2451)

Related Issues:

Code

declare module 'test' {
    // export function works
    export function myFunc(param: string): string;

    // export const doesn't work
    export const myVar: (param: string) => string;
}

declare module 'test' {
    export function myFunc(param: number): number;
    export const myVar: (param: number) => number;
}
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "useDefineForClassFields": false,
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "downlevelIteration": false,
    "noEmitHelpers": false,
    "noLib": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "esModuleInterop": true,
    "preserveConstEnums": false,
    "removeComments": false,
    "skipLibCheck": false,
    "checkJs": false,
    "allowJs": false,
    "declaration": true,
    "experimentalDecorators": false,
    "emitDecoratorMetadata": false,
    "target": "ES2017",
    "module": "ESNext"
  }
}

Playground Link: Provided

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions