TypeScript error

TS2552: A misspelled name, with a suggestion

  • Error TS2552
  • Tested with TypeScript 5.9

error TS2552: Cannot find name 'subTotal'. Did you mean 'subtotal'? is TS2304 with a suggestion: nothing called subTotal is in scope, and a declared name differs only slightly. Mixed-up capitalization is the most common cause.

At run time the same line throws ReferenceError: subTotal is not defined, but only when that line runs, and a line in an error branch may never run in testing.

At a glance

CodeTS2552
MessageCannot find name '{0}'. Did you mean '{1}'?
TypeScript's categoryerror
Listed underUnknown names and members
Turned on by No option: every checked file reports it
In .js files Reported when the file is checked: checkJs in jsconfig.json, or // @ts-check at the top of the file

The message is TypeScript's own text from its diagnostic messages file (Apache-2.0); {0} and {1} are filled in by tsc for each error.

What it looks like

tax.js Error confirmed 5.9.3 TypeScript 5.9.3, run 21 October 2026: tax.js(5,10): error TS2552: Cannot find name 'subTotal'. Did you mean 'subtotal'? 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. tax.js(5,10): error TS2552: Cannot find name 'subTotal'. Did you mean 'subtotal'? 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. tax.js(5,10): error TS2552: Cannot find name 'subTotal'. Did you mean 'subtotal'? checked 21 October 2026
/** @param {number} subtotal */
export function withTax(subtotal) {
  const taxRate = 0.08;
  return subTotal * (1 + taxRate);error TS2552: Cannot find name 'subTotal'. Did you mean 'subtotal'?
}
A misspelled variable, with the name TypeScript suggests.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["*.js"]
}

What causes it

  • The name is misspelled or capitalized differently from its declaration.
  • The name is declared in another scope (inside a different function or block) and a similar name is visible here.

How to fix it

Use the declared name

Accept the editor's Change spelling quick fix or correct the name by hand.

tax.js 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
/** @param {number} subtotal */
export function withTax(subtotal) {
  const taxRate = 0.08;
  return subtotal * (1 + taxRate);
}
The variable spelled as it was declared.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["*.js"]
}

If the name is a real global, declare it

When the name you wrote is right and comes from a script tag or the environment, the suggestion is a coincidence; declare the global as shown on the TS2304 page.

Gotchas

  • Lowercase array and promise in a JSDoc type are also reported as TS2552 under strict, with Array and Promise suggested; in JSDoc the type names are capitalized.

Sources

Last reviewed 20 October 2026.