question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use STE with namespace project?

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
KeesCBakkercommented, May 8, 2018

I’m using the following:

import { SimpleEventDispatcher, IEvent } from 'strongly-typed-events'

namespace myNamespace {
    export class MyClass {
        private _myEvent = new SimpleEventDispatcher<number>();

        public get MyEvent(){
            return this._myEvent.asEvent();
        }
    }
}

My tsconfig.json looks like this:

{
    "compileOnSave": true,
    "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "outDir": "dist",
    "declaration": true,
    "strict": true
    },
    "include": [
    "**/*.ts"
    ],
    "exclude": [
    "node_modules"
    ]
}

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.

1reaction
JohnArchercommented, May 7, 2018

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:

namespace myNamespace {
    export class MyClass {
        private _myEvent = new SimpleEventDispatcher<number>();
    }
}

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> { becomes interface 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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

When I create a new project, the using System namespace ...
If you double-click the project node in Solution Explorer, you will see the project's details in XML format. There is a <ImplicitUsings>enable</ ...
Read more >
Projects and Kubernetes Namespaces with Rancher
From the main menu, choose Projects/Namespaces. Then click Add Project. Enter a Project Name. 2. Optional: Select a Pod Security Policy​. This ...
Read more >
Using Namespaces in Different Projects in C# - Stack Overflow
There are two things you have to do: Add a reference to MyMath's dll. The MyOperations class should have a public access modifier....
Read more >
Namespaces Walkthrough | Kubernetes
This example demonstrates how to use Kubernetes namespaces to subdivide your cluster. Before you begin. You need to have a Kubernetes cluster, ...
Read more >
7: How To Create Namespaces In C# | C Sharp Tutorial
In this C# tutorial you will learn to namespaces in C# while at the same time organizing your project into different directories.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found