- Error
- Reported by the type checker
TS2708
Cannot use namespace '{0}' as a value.
A namespace with only types is used as a value. Use one of its exported values, or refer to it in a type position only.
What it means
The namespace contains only types (for example interfaces), so there's no object for it at runtime. Using its name in an expression is an error.
Example
namespace Api {
export interface Request { url: string }
}
const a = Api;
export {};
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(4,11): error TS2708: Cannot use namespace 'Api' as a value.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Use it only in types:
let r: Api.Request. - If you need a runtime object, export values from the namespace or use a plain object.