admin管理员组文章数量:1332377
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.
本文标签: javascriptExport function in TypescriptStack Overflow
版权声明:本文标题:javascript - Export function in Typescript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742298105a2449133.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论