Quick Answer
Attempting to use a namespace as a type
Understanding the Issue
In TypeScript, namespaces and types are distinct concepts. This error occurs when you try to use a namespace (container of code) where a type is expected.
The Problem
This code demonstrates the issue:
Typescript
Error
// Problem: Using namespace as type
namespace MyNamespace {
export function demo() {}
}
let x: MyNamespace; // Error
The Solution
Here's the corrected code:
Typescript
Fixed
// Solution 1: Export a type
namespace MyNamespace {
export interface MyType {}
}
let x: MyNamespace.MyType; // OK
// Solution 2: Use typeof for values
const y: typeof MyNamespace.demo; // OK
Key Takeaways
Ensure you reference actual types, not namespaces, in type annotations.