Skip to content

@typescript-eslint/unbound-method error when using JSDoc @this {void} or alternativesΒ #62371

@OhiraKyou

Description

@OhiraKyou

πŸ”Ž Search Terms

"unbound-method", "this {void}", "this: void"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about @this, this: void, or "unbound".

⏯ Playground Link

https://typescript-eslint.io/play/#ts=5.9.2&fileType=.js&code=FDDGBsEMGdoAgKoBcCW4WoKbwN7DnAPQBUx%2BBxcAAkgBYq4BuA9igCYC%2B5clVADpABOkALZwc0JIJQA7AOYc4I7NEhzM3YoXKTIqUHABmAVxmhUzGQBVaegCLNsAOWZIE0TDYYAKZbDWYAJTi3HCgltDM4JgAdODMcr4qAYEA3ORcXMAkZDxwABLMjJjS8nBFJXB0mHC6%2Bkam5iiWcLQlNYKYxZDg8HR6cAAGdAwAXHAs7INwDHA9nZBsAJ5zfHzomGwx%2BJSFAO5dJQA0VW1wJYLMgnB8JdAMSNDbPNrhMpK1tFf9MmxwALyIVDoLBPExmCzWWxIBzOVzuTz0aDpYDQL6CH5sbwAIncsjkpxqaO%2Btl%2BMWxaWAQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6WJgIwHsOATWgFtE%2BABbc%2B6KImjRu0SODABfEMqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

πŸ’» Code

Using @this {void}:

class Utilities {
	/**
	 * @this {void}
	 * @param {string} message
	 */
	static functionThatDoesNotUseThis(message) {
		console.log(message);
	}
}

/**
 * Hovering over the static function here reveals that `this: void` is already applied.
 * However, the `@typescript-eslint/unbound-method` error suggests applying it.
 */
const shorthand = Utilities.functionThatDoesNotUseThis;

With a function signature type:

class Utilities {
	/**
	 * @type {(this: void, message: string) => void}
	 */
	static functionThatDoesNotUseThis(message) {
		console.log(message);
	}
}

const shorthand = Utilities.functionThatDoesNotUseThis;

With a separate .ts file and JSDoc import:

// types.ts
export type DoThingFunction = (this: void, message: string) => void;

// Main script
class Utilities {
	/**
	 * @type {import("./types.ts").DoThingFunction}
	 */
	static functionThatDoesNotUseThis(message) {
		console.log(message);
	}
}

const shorthand = Utilities.functionThatDoesNotUseThis;

πŸ™ Actual behavior

ESLint suggests to mark this: void, despite the editor showing that it already has been.

πŸ™‚ Expected behavior

I expect no @typescript-eslint/unbound-method error when using @this {void} on a static function and assigning it to a variable.

Additional information about the issue

I reported this on the typescript-eslint repo, but it was closed as a TypeScript issue.

Also, when I created the playground (from the TypeScript ESLint issue template), the this: void was visible in the static function's signature when hovering over it. But, when I return to the link, it isn't, and the config tabs are not accessible. So, your mileage may vary with the playground.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions