TypeScript: Module Augmentation fails when exports are declared in an ExportClause

TypeScript Version:

nightly (1.9.0-dev.20160502)

Code

// ext1.d.ts
declare module "State" {
    interface IState {
        num: number;
    }
    export { IState };
}

// ext2.d.ts
declare module "State" {
    interface IState {
        str: string;
    }
    export { IState };
}

//app.ts
import { IState } from "State";

function test(state: IState): void {
    console.log(state.num);
    console.log(state.str);
}

// tsconfig.json
{
    "files": [
        "app.ts",
        "ext1.d.ts",
        "ext2.d.ts"
    ]
}

Expected behavior: The “State” module and IState interface declarations should be merged and the code should compile without errors.

Actual behavior: The declaration files report error TS2300: Duplicate identifier 'IState'

Workaround: The above errors do not occur when both IState interfaces are exported inline using the export modifier instead of in a ExportClause. NOTE: If the first is exported inline and the second is exported in an ExportClause then the second declaration errors with TS2482: Export declaration conflicts with exported declaration of 'IState'.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

We’re seeing a similar error. After doing npm install ag-grid --save, we tried to augment the module as follows.

// augmentation.d.ts
import agGrid = require("ag-grid");

declare module "ag-grid" {
    interface ColDef {
        str: string;
    }
}

On build with tsc 2.4.1 we see the following error:

node_modules/ag-grid/main.d.ts(135,10): error TS2484: Export declaration conflicts with exported declaration of ‘ColDef’.

We have also tried this approach:

// augmentation.d.ts
declare module "ag-grid" {
    interface ColDef {
        str: string;
    }
}

In that case, the actual behavior is that the ColDef interface now has only the str property.

// index.ts
import { ColDef } from "ag-grid";

let def: ColDef;

image