-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Proposal for module / namespace behavior to allow class-per-file development approach #15827
Comments
As I was thinking about it during the night, although it would be very nice and helpful, it would be probably very very hard (I would almost say impossible) to implement. But what about adding something like
directive which would be replaced by the code from the file specified during the compile time? in such case, we well be able to achieve almost everything, splitting modules per multiple files, splitting namespaces per multiple files, moreover splitting a class over multiple files. Of course, nothing is ideal and I can see some problems here, such as: file1.ts
file2.ts
file3.ts
Also, IDE integration could be problematic as it would require to know in what context the the file is included to have the intellisense / type checking available while editing the include file. But the primary purpose of it should not be reusing of the piece of the code anywhere, so it can be somehow limited, i.e. the given file can be included just once per a program. Yes, I can use external tool for this. But what about IDE integration? In case of VS there is no possibility how to integrate 3rd party tool to tsbuild process which the language service will take care about as VS extension source is not available. Or is it? By the way, I think this is only the one problem we are walking around here over multiple issues. It's possible to use 3rd party tools for such cases, I would write a pre/post processors taking care of #IFDEFS, ///<include directive handling, module and namespace merging and whatever else including correct .post-build map file remapping after compilation. This from my perspective correct way how to implement such features while not touching the compiler itself. But its useless until language service will be able to provide a the complete build info (including 3rd party tools) to IDE. |
How is this different from #447? and why do we need two issues to track the same suggestion?
Please see #17. We have decided to keep modules aligned with what ES6 stipulated. For merging modules, you can use a tool like webpack or browserify to bundle them.
I would recommend using ES6 modules for these. The pattern i would use us, each component/class/logical unit lives in its own module (i.e. file). in each folder you have collection of modules that belong together, and then add a single entry point, call it export * from "./mod1";
export * from "./mod2";
... |
Its different because it includes two things, modules an namespaces.
Although I don't understand your decision so much I I have to live with it. Its probably related to the fact the TypeScript is not working with the project as with real project but rather it compiles each file separately so it would be hard to do it in a different way. Unfortunately, I didn't find a way how to use mentioned tools in my project but it would be for longer discussion which I don't want to open here.
So you recommend me to have a separate ES6 module for each file then reexport their exports. This means to have a separate ES6 module for each class and each interface (moreover for additional, supporting code). This also means to have tons of d.ts files. Its not very practical and again it will require some kind of post-build tool to put them together to be usable for the whole module. And export almost everything in internal modules of the module. |
Modules and namespaces are two different beasts. we have tried in our early days (hence the use of the same keyword to define both constructs) to consolidate both, and could not make that work. that is why we later on added the keyword Any proposal here needs to be clear about what it handles and not lump them together, cause they are not lump-able.. multi-file modules was tracked by #17, and i do not think there is any new information to change this decision. namespaces are already bundled using I would recommend looking into webpacl, browserify, or rollup for bundling options.
Well putting every interface/class/helper function in a file is up to you. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
This is related to #447 but it seems nobody is reading it anymore.
From my perspective, the typescript compiler should do combine same namespaces to the same IIFE, even if its splitted over multiple files. Otherwise its not the same namespace. And its confusing as in real, the 'namespace' keyword is not TypeScript namespace, but JavaScript namespace. Moreover, same named modules splitted over multiple files should be also combined to single output js file to be possible to split AMD, CommonJS or SystemJS module to mutiple files.
I know you are trying to keep as close as possible to ES spec and there is no such possibility to split anything over multiple files but it will be really helpful.
Consider we have a project with the following folder structure:
a and b are modules, Ns are namespaces. Export file (module_exports.ts) should be possible to be used as is should be simply possible to define and find out what we are exporting out of the module without need of looking to all files in the module folder structure. Of course, export/reexport of the class, function, namespace or whatever else should be possible from any file in the same module scope, but will be messy in big projects.
The compilation output should be a.js , b.js and blah.js according to definition in files:
module_exports.ts
ClassA.ts:
ClassB.ts:
tools.ts
I will not write the code for the b folder branch as it is hopefully clear from previously mentioned code.
Please note the module keyword is supposed to be a AMD, UMD, CommonJS or SystemJS module, not a module pattern from Javascript.
The text was updated successfully, but these errors were encountered: