-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Why TS generates two functions, but not one?
We have one module separated between two files in TS, or in one file, but separated by other code. And we need to call F1 from F2. But do not need to cal F1 outside of Main module. Now we can write just like this:
module Main {
export function F1() {
}
}
module Main {
export function F2() {
F1();
}
}And it compiles to JS as two independent functions, so user can access F1 function:
var Main;
(function (Main) {
function F1() {
}
Main.F1 = F1;
})(Main || (Main = {}));
var Main;
(function (Main) {
function F2() {
Main.F1();
}
Main.F2 = F2;
})(Main || (Main = {}));But it seems to me that it will be better to concatenate the content of the modules with single name to one function. Like this JS output:
var Main;
(function (Main) {
function F1() {
}
function F2() {
F1();
}
Main.F2 = F2;
})(Main || (Main = {}));So there will be no need to create additional export members just to allow execute one members from the others inside one module.
p.s. Such code will fail:
module Main {
function F1() {
}
}
module Main {
export function F2() {
F1(); // error TS2304: Cannot find name 'F1'.
}
}Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created