-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
How to build a project webpack with namespaces? #18240
Comments
Hey there, this issue tracker isn't meant to work as a support forum. These questions tend to be better suited for StackOverflow. You may want to open a question up there instead. Thanks! For the record, you have namespaces that are in global files (i.e. files that have no |
@DanielRosenwasser The fact that I'm writing a library which has only one entry point. That is, in order for it to work correctly, the Declaration must export only one module, and the description must be in a namespace. But generators .d.ts declare module for each module. But this is not correct. To rewrite by hand the modules namespace is not very desirable. What to do in such cases? On so on complex issues-rare issues quoting the documentation, which I know by heart. And the answer You gave me, I already know. I thought that there is something not documented, especially for such cases. |
Typically when people have a single entry point, the import the sub-modules into the main module which provides the single entry point. Again this isn't TypeScript thing, it is more how to properly structure web application code. |
@kimamula I understand it! But the Declaration is generated for each module at a time as you need only one, which is the entry point. hide other modules by using namespace. But namespace doesn't work with modules. I do not understand why typescript is not provided. Batman.ts
Superman.ts
hero.ts
hero.d.ts
You can say anything, but this declaration will still be wrong. |
I don't think you understand modular/UMD declarations and instead of trying to force ambient/global declarations where they are not required or needed. UMD declarations were introduced in TypeScript 2.0 and are the best way to deal with distributing modular code as a library. When you emit modules with the You keep saying "we aren't listening" or "don't understand" but honestly, I am the project lead for a large library built on TypeScript with hundreds of modules in 20+ packages (@dojo). I might actually know what I am talking about. |
I began to write in js, even when es5 was not and went through the entire evolution of the modules until today. But I don't understand why typescript perverted es6 modules. why was it necessary to introduce a namespace and others? I would be very grateful if You would my code showed how to do that in typescript.
Yes, but the entry point one! Autocompletion will display me as "Batman" and "hero/Batman". First way will result in an error. You can create ten large projects, but the knowledge they will not add, if You're so confident. And can give You advice functions validators made to stand in a separate file, instead of writing them as a schoolboy in the file, where the declared class. |
The namespace syntax was a solution to an early spec solution of ES Modules. TypeScript continued to adapt as the standard evolved, but to avoid breaking syntax backwards compatibility was preserved. That is not the way to structure your code these days as both I and Daniel have indicated. You ask for help and then suggest that I am not capable of helping you (and essentially insult me). Clearly I am not capable of helping you. Good luck in your endeavours. |
@kitsonk I'm sorry that You are offended by the words of the school code. But it's true.You have to config the build I saw nothing special, except for obsolete grunt. So Your words about denial of care seem to me to be a whimsical attempt to hurt me. nevertheless, the problem exists, but I guess You really don't realize it. I spent the whole day reading github and so, but on similar issues, I see only links to very different topics. |
😄 |
@acopalipsis the most efficient way I found is this one:
same for Superman
|
I have exactly the same problem as OP described. I even got further by setting the I finally decided to not use namespace and modules at all and just use TypeScript as a typechecker more than a module resolver. It's just so frustrating that these little annotations do not work. I think it would be perfect to have something like that: // internalLogic1.ts
/** @internal */
export function internalLogic1() {
} // internalLogic2.ts
/** @internal */
export function internalLogic2() {
} // awesomeHelper.ts
import { internalLogic1 } from './internalLogic1'
import { internalLogic2 } from './internalLogic2'
export function awesomeHelper() {
internalLogic1()
internalLogic2()
} And only have the following output (with ts-loader): $ ls dist
awesomeHelper.js
awesomeHelper.d.ts What is currently happening is that the bundle get compiled correctly, but we end up with that structure: $ ls dist
awesomeHelper.js
awesomeHelper.d.ts
internalLogic1.d.ts
internalLogic2.d.ts Which is not the expected behavior for someone who want to make a library for Node & Web targets. Which is why Webpack is helping in this way with the |
Batman.ts
Superman.ts
hero.ts
webpack compile
If you remove the namespaces, then the project compiles as expected. But with namespaces is compiled only hero.ts. What's the matter?
I need the Declaration of the wrapped contents into namespaces. And important condition is to collect project webpack.
The text was updated successfully, but these errors were encountered: