Usages of "declare"

Topics: Language Specification
Mar 23, 2014 at 9:47 AM
Edited Mar 23, 2014 at 9:56 AM
It seems that it's not very clear about the usage of "declare" in the doucment of TypeScript in different kinds of situations. And I find:

1) declare var Variable:Type; // The Variable must be pre-defined.

2) declare function ……; //A pre-defined function with the same name

3) But for module!
If I have a class of TypeScript:
module MyModule
{
      export class HelloWorld {
        public Click(): void {
            alert("OK");
        }
    }
}
var HW: MyModule.Helloworld = new MyModule.Helloworld();
However when I define a declaration file for that:
declare module MyModule {
     class HelloWorld  {
        public Click(): void;
    }
}
This is wrong! and it will tell me that duplicated of "HelloWorld"? Why? Don't you say "declare" should be used to modify an existing thing? How many ways of usages of "delare"? I feel very puzzled......
Developer
Mar 24, 2014 at 5:14 PM
If you're getting an error about a duplicate definition for HelloWorld then it's because you have 2 files open in Visual Studio which each define it in the same module. Declare works the same way on all elements, it declares type information without causing any corresponding JavaScript to be emitted.
Marked as answer by ProgramVolunteer on 3/26/2014 at 11:04 PM
Mar 25, 2014 at 7:02 AM
danquirk wrote:
If you're getting an error about a duplicate definition for HelloWorld then it's because you have 2 files open in Visual Studio which each define it in the same module. Declare works the same way on all elements, it declares type information without causing any corresponding JavaScript to be emitted.
Sorry but I mean that since you have a variable defined, you can use "declare" for the variable. So Why cannot we use declare to the existing module?