TypeScript error

TS7034: A variable whose type cannot be settled

  • Error TS7034
  • Reported with noImplicitAny
  • Reported with strict
  • Tested with TypeScript 5.9

error TS7034: Variable 'tags' implicitly has type 'any[]' in some locations where its type cannot be determined. is reported on a declaration such as let tags = []; or let config;, and TS7005 (Variable 'tags' implicitly has an 'any[]' type.) on the places that read it.

The checker can usually follow such a variable: after tags.push("a") in the same function it knows tags holds strings. It loses track when the variable is captured by another function (a callback, an arrow function) or exported, because it cannot know when that other code runs. Then the variable is any, and noImplicitAny reports it.

At a glance

CodeTS7034
MessageVariable '{0}' implicitly has type '{1}' in some locations where its type cannot be determined.
Also on this page: TS7005 Variable '{0}' implicitly has an '{1}' type.
TypeScript's categoryerror
Listed underImplicit any
Turned on by noImplicitAny, strict
In .js files Reported when the file is checked: checkJs in jsconfig.json, or // @ts-check at the top of the file

The messages are 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

tags.js Error confirmed 5.9.3 TypeScript 5.9.3, run 21 October 2026: tags.js(3,7): error TS7034: Variable 'tags' implicitly has type 'any[]' in some locations where its type cannot be determined. tags.js(7,10): error TS7005: Variable 'tags' implicitly has an 'any[]' type. tags.js(11,12): error TS7005: Variable 'lastError' implicitly has an 'any' type. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. tags.js(3,7): error TS7034: Variable 'tags' implicitly has type 'any[]' in some locations where its type cannot be determined. tags.js(7,10): error TS7005: Variable 'tags' implicitly has an 'any[]' type. tags.js(11,12): error TS7005: Variable 'lastError' implicitly has an 'any' type. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. tags.js(3,7): error TS7034: Variable 'tags' implicitly has type 'any[]' in some locations where its type cannot be determined. tags.js(7,10): error TS7005: Variable 'tags' implicitly has an 'any[]' type. tags.js(11,12): error TS7005: Variable 'lastError' implicitly has an 'any' type. checked 21 October 2026
export function collectTags() {
  let tags = [];error TS7034: Variable 'tags' implicitly has type 'any[]' in some locations where its type cannot be determined.
  const add = (/** @type {string} */ tag) => tags.push(tag);
  add("sale");
  return tags;error TS7005: Variable 'tags' implicitly has an 'any[]' type.
}

export let lastError;error TS7005: Variable 'lastError' implicitly has an 'any' type.
A variable whose type the checker cannot settle.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["*.js"]
}

What causes it

  • A variable is declared with [], null, undefined or no value, and it is used inside a nested function or exported (export let lastError; is reported on its own as TS7005).
  • noImplicitAny is on (part of strict).

How to fix it

Annotate the variable

/** @type {string[]} */ above let tags = [];, or /** @type {Error | undefined} */ above export let lastError;. The annotation fixes the declaration and every TS7005 that came from it.

tags.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
export function collectTags() {
  /** @type {string[]} */
  let tags = [];
  const add = (/** @type {string} */ tag) => tags.push(tag);
  add("sale");
  return tags;
}

/** @type {Error | undefined} */
export let lastError;
Annotate the variable, or give it a value of the right type.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["*.js"]
}

Gotchas

  • Without a closure the same let list = []; list.push("a"); return list; passes: the checker follows the pushes and types list as string[].
  • An empty array assigned to a class field reports TS7008 instead.

Sources

Last reviewed 20 October 2026.