namespace / module: Duplicate declaration & needlessly remove line-breaks
See original GitHub issueI wonder why TSC re-declare a global var after each namespace or module block.
namespace OurName {
export var isAndroid = true;
export var isWinPhone = false;
// do something
var checkCookies = function() {
return true;
}
}
namespace OurName {
export var HTML = '<b>hello</b>';
export var state = [1, 2, 3];
export var addToCart = function() {
return true;
}
}
namespace OurName {
var xyz = false;
// do something
export module Office {
var isClosed = false;
}
}
Above code is translated to:
var OurName;
(function (OurName) {
OurName.isAndroid = true;
OurName.isWinPhone = false;
// do something
var checkCookies = function () {
return true;
};
})(OurName || (OurName = {}));
var OurName;
(function (OurName) {
OurName.HTML = '<b>hello</b>';
OurName.state = [1, 2, 3];
OurName.addToCart = function () {
return true;
};
})(OurName || (OurName = {}));
var OurName;
(function (OurName) {
var xyz = false;
// do something
var Office;
(function (Office) {
var isClosed = false;
})(Office = OurName.Office || (OurName.Office = {}));
})(OurName || (OurName = {}));
It also removes the line-breaks that help me keeping the code easier to look. I am porting our production ES5 code to TypeScript, so I have to carefully re-check the output of TSC. This behaviour makes my work even harder.
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Removing duplicate namespaces in XML Literals (Shyam ...
Yes, the LINQ to XML API can figure out and remove duplicate namespaces. But it does not enforce the removal of duplicate namespaces...
Read more >eslint-plugin-import | Yarn - Package Manager
This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, and prevent issues with misspelling of file paths and import names. All...
Read more >node_modules/eslint-plugin-import/CHANGELOG.md · master ...
no-unused-modules : consider exported TypeScript interfaces, types and enums (#1819, ... [readme] Remove duplicate no-unused-modules from docs (#1690, ...
Read more >RHSA-2021:3759 - Security Advisory - Red Hat 客户门户网站
... BZ - 1967621 - Operator fails to install and OLM tries to delete nonexistent catalog pods under openshift-marketplace/redhat-marketplace ...
Read more >SWIG-4.0 Documentation
i */ %module example %{ /* Put headers and other declarations here */ extern double My_variable; extern int fact(int); extern int my_mod(int n,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Should be fixed by https://github.com/Microsoft/TypeScript/pull/11286
If support output formatting adds much complexity like you said, so we don’t need to do it. Just try to make the output easier to look at by adding a line-break after each block. For example:
Or add line breaks before and after a function/namespace/module declaration. (optionally)
Does it easier to look? I know that using line-breaks for formatting code are not a priority in many style guides. But for those who don’t have good eyesight like me (short-sighted: 6.25 & astigmatism: 2.25), it truly helps much.