TypeScript error

TS2683: this has no type in a plain function

  • Error TS2683
  • Reported with noImplicitThis
  • Reported with strict
  • Tested with TypeScript 5.9

error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. is reported when this is used in a function that is not a method of a class or an object literal, so the checker has no way to know what it will be. With noImplicitThis on (part of strict), that any is an error.

In browser JavaScript the typical case is a named function used as an event handler: addEventListener calls it with this set to the element. The checker does not read that from the later addEventListener call, because the function is declared on its own.

At a glance

CodeTS2683
Message'this' implicitly has type 'any' because it does not have a type annotation.
TypeScript's categoryerror
Listed underImplicit any
Turned on by noImplicitThis, strict
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).

What it looks like

menu.js Error confirmed 5.9.3 TypeScript 5.9.3, run 21 October 2026: menu.js(3,3): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. menu.js(3,3): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. menu.js(3,3): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. checked 21 October 2026
export function toggleOpen() {
  this.classList.toggle("open");error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
}

document.querySelector("nav button")?.addEventListener("click", toggleOpen);
this in a function that is not a method.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["*.js"]
}

What causes it

  • A function declaration or expression uses this and is not part of a class or object literal.
  • noImplicitThis is on (part of strict).

How to fix it

Declare this with @this

/** @this {HTMLElement} */ above the function gives this a type. Calling the function some other way, without the right this, is then reported.

menu.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
/** @this {HTMLElement} */
export function toggleOpen() {
  this.classList.toggle("open");
}

document.querySelector("nav button")?.addEventListener("click", toggleOpen);

/** @param {Event} event */
export function toggleFromEvent(event) {
  if (event.currentTarget instanceof HTMLElement) event.currentTarget.classList.toggle("open");
}
Say what this is with @this, or use the event.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["*.js"]
}

Or use the event instead of this

event.currentTarget is the element the listener is on. It is typed EventTarget | null, so check it with instanceof HTMLElement before using element properties. This also works in arrow functions, which have no this of their own.

Gotchas

  • A function that assigns to this.something is treated as a constructor function in a .js file, and this inside it is not reported.
  • At the top level of a module, this is undefined; an arrow function there that uses this gets a different error (the value may be undefined) rather than TS2683.

Sources

Last reviewed 20 October 2026.