Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module augmentation with export list #9127

Open
paleo opened this issue Jun 13, 2016 · 1 comment
Open

Module augmentation with export list #9127

paleo opened this issue Jun 13, 2016 · 1 comment
Labels
Bug A bug in TypeScript
Milestone

Comments

@paleo
Copy link

paleo commented Jun 13, 2016

TypeScript Version:

1.8.10

Code

// scale.ts
class Scale {
    weightOnEarth(mass) {}
}
export { Scale }
// advancedScale.ts
import {Scale} from "./scale" ;

declare module "./scale" {
  interface Scale {
    weightOnMoon(mass);
  }
}
Scale.prototype.weightOnMoon = function (ee) {
}
// consumer.ts
import { Scale } from "./scale";
import "./advancedScale";

let scale: Scale;
scale.weightOnMoon(10);  // ok
scale.weightOnEarth(10);
// tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5"
  }
}

Bug 1

This code is from this post, with just a small change: in scale.ts, the syntax of export list is used export { Scale }.

The compiler returns errors:

scale.ts(5,10): error TS2484: Export declaration conflicts with exported declaration of 'Scale'
advancedScale.ts(9,1): error TS2304: Cannot find name 'Scale'.
consumer.ts(7,7): error TS2339: Property 'weightOnEarth' does not exist on type 'Scale'.

Bug 2

With the original code, in consumer.ts, the line import "./advancedScale"; can be removed but the code still compiles.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 13, 2016

Issue 2, is expected, since you have a tsconfig.json with no "files" or "exclude" list, and that tells the compiler to include all files. so the file is included whether you import it or not.

issue 1 is the real problem here. the work around is to export the declaration and not use an export statement:

// scale.ts
export class Scale {
    weightOnEarth(mass) {}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants