I have a .ts
file with a module and a function outside module like this:
$(function () {
populate()
});
function populate() {
...
}
module portfolio.charts {
export function foo(){
...
}
}
Using Typescript piler mand tsc --declaration
the declaration file is created. This .d.ts
file contains the following code:
function populate(): void;
module portfolio.charts {
function foo(): void;
}
Why populate()
function and portfolio.charts
module are exported? I thought it was necessary the keyword export
to export a function or a module. If I add the d.ts
file as a dependency on another file I can use all functions and the module. Can I declare them private? Thanks and sorry for my english.
I have a .ts
file with a module and a function outside module like this:
$(function () {
populate()
});
function populate() {
...
}
module portfolio.charts {
export function foo(){
...
}
}
Using Typescript piler mand tsc --declaration
the declaration file is created. This .d.ts
file contains the following code:
function populate(): void;
module portfolio.charts {
function foo(): void;
}
Why populate()
function and portfolio.charts
module are exported? I thought it was necessary the keyword export
to export a function or a module. If I add the d.ts
file as a dependency on another file I can use all functions and the module. Can I declare them private? Thanks and sorry for my english.
1 Answer
Reset to default 7The TypeScript specification is a bit dry on this, so here are some examples.
Example 1
module MyModule {
class MyClass {
myFunction() {
alert('Test');
}
}
function myOtherFunction() {
alert('Test Again');
}
}
In this example, MyModule
is a global module (it isn't inside of any other module) so this will appear in the definition file. MyClass
,myFunction
and myOtherFunction
are invisible in the definition:
module MyModule {
}
So to make something visible in your declaration, it either...
Needs to be in the global scope, like
MyModule
or likepopulate
in your example, orNeeds to be prefixed with the
export
keyword
In your example, point 1 applies.