How to properly use namespace with external modules in TypeScript?
Hi! I'm learning TypeScript and trying to structure my project. Previously I used namespaces to organize code within a single file, but now that the project has grown, I want to split the code into separate modules (files).
The problem is that when I try to import a module that contains a namespace, I get errors or the namespace doesn't work as I expect.
Here's an example of what I'm doing:
I have a file `math.ts`:
```typescript
namespace MathUtils {
export function add(a: number, b: number): number {
return a + b;
}
export function subtract(a: number, b: number): number {
return a - b;
}
}
```
And a file `app.ts`:
```typescript
import { MathUtils } from './math';
console.log(MathUtils.add(5, 3)); // Error: Mat
No answers yet.
Log in to leave an answer
Blogs
WebSocket in Swift: Building Real-Time Applications for iOS and macOS