-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: importing internal modules with ES6 syntax #2630
Comments
These two do not mean the same thing. import "Lib/Utils" is an ES6 module import that is already supported in TypeScript 1.5. and as per the ES6 module semantics, it turns your file into an external module that has a dependency on another module Lib/Utils. by turning it into an external module it implies that you have a module system that will load your dependencies, be that AMD (requirejs for instance) CommonJS (if you are writing a node app), or ES6 modules (if you are on an ES6-enabled engine that supports modules). On the other hand:
Is a TypeScript compiler directive to help the compiler figure out the context without specific all files on the command line. the file is not considered an external module, and there are no run time dependencies added. I do not think we want to overload the ES6 |
A patch would not be accepted. We don't want the language to have confusing constructs in it, or more ways to import/export than we already have (which is too many to begin with). |
After thinking a little bit more about it, I don't think supporting ES6 for importing internal modules would be confusing at all. Even now, the import syntax can have different meanings (it could mean importing CommonJS modules, or importing AMD modules, or importing ES6 modules). So we have 2 scenarios (assuming Foo.ts includes ES6 import directive):
So, why not? Internal modules can be seen as just another module system. If there's still any confusion, then perhaps adding a new module flag (eg. "-m internal") would solve the issue? The "///<reference" syntax is far worse. |
@jbondc The current ways to use modules are absolutely confusing. However, it is not the case that doing different things the same way automatically reduces confusion. It can actually create more confusion when seemingly identical things now have different (either subtly different or very different) behavior. As a concrete example, consider internal vs external modules today. They're sort of similar so they were both called modules. You use the module keyword with each. But it turns out that actually creates more confusion than naming them discretely and so we're currently considering using 'namespace' going forward rather than 'internal module.' |
We have to keep supporting /// references for the foreseeable future. same for import = require, and the new import syntax. this adds yet another variant. |
Of course module vs namespace is a different issue. The point was merely to illustrate how an apparent reduction in complexity (1 keyword instead of 2) can actually be the opposite. In addition, as Mohamed notes in the near term you automatically add complexity as long as you're continuing to support the old solution (which we must) so the value of the simplification must be significant. We have already gotten feedback that many people don't like the behavior where you cannot read an |
Personally, I think the correct way to solve this is to have a clean and complete module story, so you do not need to /// reference your way out of problems. |
-1 |
@M-jerez can you take a look at handbook at: https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Namespaces%20and%20Modules.md, and let us know what topics need more coverage? |
@mhegazy this is actually a very good documentation it would be great to have a link to it from the official website http://www.typescriptlang.org/Handbook#modules. I just couldn't find it before (it is appearing in google search now), thanks for pointing it. |
+1 on simplifying the internal module usage syntax. |
It would be nice to import internal modules with ES6 syntax. Example:
you could write...
... instead of the old way
/// <reference path="Lib/Utils.ts"/> // old syntax
The text was updated successfully, but these errors were encountered: