How to use STE with namespace project?
See original GitHub issueI am relatively new to TypeScript, so excuse me if that is a dumb question.
My web project is build with namespaces (https://www.typescriptlang.org/docs/handbook/namespaces.html) instead of modules. I use the latest version of STE, so I updated my package.json like so and did an npm install (all fine):
"ste-core": "^1.4.3",
"ste-events": "^1.4.3",
"ste-signals": "^1.4.3",
"ste-simple-events": "^1.4.3",
"strongly-typed-events": "^1.4.3"
Now, with namespaces I do not use import statements, if I understand it correctly (when I try it it breaks my code). So normally I just write var ttt = new SimpleEventDispatcher<number>();
. But the compiler tells me that it cannot find name SimpleEventDispatcher and so on.
One possibility is to declare a reference path like ///<reference path="..\node_modules\ste-simple-events\dist\index.d.ts"/>
. But this leads this error:
node_modules/ste-simple-events/dist/definitions.d.ts(1,69): error TS2307: Cannot find module 'ste-core'.
I tried a test project using no namespaces but import statements and this does work. So the question is, is there a way to use it with namespace style and/or do I something wrong? Thanks a lot!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:12 (6 by maintainers)
I’m using the following:
My tsconfig.json looks like this:
I’ve added a zip with the info here: https://www.dropbox.com/s/ap9fwhyiygku8pp/STE-24.zip?dl=0
Please let me know what I’m missing. I only installed
"strongly-typed-events": "^1.4.3"
in this example.The other packages: Yeah, I already thought that, but wanted to make sure that I really have all I need. But thanks for the hint.
Here is same simple sample code:
This leads to “Cannot find name ‘SimpleEventDispatcher’.”
I did a little test with STE 1.0.1 where you shipped a single .d.ts file. I get it to work with namespaces, when I modify that file in the way that I delete all occurrences of the key word “export” (export
interface IEventHandler<TSender, TArgs> {
becomesinterface IEventHandler<TSender, TArgs> {
) and delete the complete last line (export default StronglyTypedEventsStatic;
).After savong these modifications (as strongly-typed-events.global.d.ts) I can “import” the definition by writing:
///<reference path="vendor/strongly-typed-events.global.d.ts"/>
So, I think I would need such a merged definition file. I am not sure if you can generate that automatically?
Thanks for your help anyway! Your library is very nice and helpful!