@namespace Format is a JSDoc documentation tag that groups related functions under one name in the documentation. TypeScript 5.9 does not read it: a standalone /** @namespace Format */ comment declares nothing, so Format.price() is an error because Format does not exist.
In JavaScript the grouping is an object. Declare const Format = {} and assign functions to its properties, or write the object literal with the functions inside it. TypeScript adds each assigned property to the object's type.
At a glance
| Use | JSDoc in a .js file | TypeScript in a .ts file |
|---|---|---|
| An object that groups functions | export const Format = {};
/** @param {number} amount */
Format.price = (amount) => …; | export namespace Format {
export const price = (amount: number) => …;
} |
Examples
/** @namespace Format */
/**
* @memberof Format
* @param {number} amount
*/
export function price(amount) {
return `$${amount.toFixed(2)}`;
}
Format.price(19.5);error TS2552: Cannot find name 'Format'. Did you mean 'FormData'?jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": ["*.js"]
} export const Format = {};
/** @param {number} amount */
Format.price = (amount) => `$${amount.toFixed(2)}`;
/** @param {number} grams */
Format.weight = (grams) => (grams >= 1000 ? `${grams / 1000} kg` : `${grams} g`);
Format.price(19.5);
Format.weight(1250);export namespace Format {
export const price = (amount: number) => `$${amount.toFixed(2)}`;
export const weight = (grams: number) => (grams >= 1000 ? `${grams / 1000} kg` : `${grams} g`);
}
Format.price(19.5);
Format.weight(1250);jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": ["*.js"]
} How we tested it
The first example declares @namespace Format in a comment, files price under it with @memberof, and calls Format.price(). tsc reports that it cannot find the name Format (TS2552, with a spelling suggestion), so neither tag creates anything.
Objects as namespaces
In a .js file, const Format = {} followed by Format.price = … and Format.weight = … gives Format both properties, with the types of the assigned functions. The assignments must be in the same file as the declaration.
The TypeScript tab shows a namespace declaration, which is TypeScript syntax and cannot be written in a .js file. A plain object or a module of named exports is the JavaScript equivalent.
Gotchas
- An ES module is usually the better grouping:
import * as Format from "./format.js"gives the sameFormat.pricecall with no object to maintain. - Keep
@namespaceif your documentation tool needs it; TypeScript shows it in the hover as text.
Questions
Can I declare a TypeScript namespace in JavaScript?
Not with a tag. Use an object or a module in the .js file, or write declare namespace in a .d.ts file if the namespace already exists at run time (a global from a script tag, for example).
Sources
- @namespace · JSDoc
- Type Checking JavaScript Files: property assignments · TypeScript handbook
- JSDoc Reference · TypeScript handbook
Last reviewed 20 October 2026.