JSDoc tag

@namespace

  • Not checked by TypeScript
  • Tested with TypeScript 5.9

@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

format.js Error confirmed 5.9.3 TypeScript 5.9.3, run 21 October 2026: format.js(12,1): error TS2552: Cannot find name 'Format'. Did you mean 'FormData'? 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. format.js(12,1): error TS2552: Cannot find name 'Format'. Did you mean 'FormData'? 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. format.js(12,1): error TS2552: Cannot find name 'Format'. Did you mean 'FormData'? checked 21 October 2026
/** @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'?
@namespace does not declare anything.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["*.js"]
}
format.js format.ts TypeScript 5.9.3 TypeScript 5.9.3, run 21 October 2026: No errors. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. No errors. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. No errors. checked 21 October 2026
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);
An object with properties is the JavaScript namespace TypeScript reads.
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 same Format.price call with no object to maintain.
  • Keep @namespace if 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

Last reviewed 20 October 2026.