Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cannot use "this" in a typescript function declaration #919

@a88zach

Description

@a88zach

Expected behavior

A user should be able to document a function in Typescript that uses the "this" keyword

Actual behavior

Conflicting rules prevent this from passing warnings.

  • When @param this is declared the warning is:
    Screen Shot 2022-10-19 at 10 08 32 AM

  • When @param this is removed the warning is:
    Screen Shot 2022-10-19 at 10 09 13 AM

ESLint Config

module.exports = {
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:jsdoc/recommended',
  ],
  overrides: [],
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint', 'jsdoc'],
  root: true,
  rules: {
    'jsdoc/require-param-type': 0,
    'jsdoc/require-returns-type': 0,
    'jsdoc/no-types': 2,
  },
};

ESLint sample

Screen Shot 2022-10-19 at 10 08 32 AM

type T = { name: string };

/**
 * @param this desc
 * @param bar number to return
 * @returns number returned back to caller
 */
function foo(this: T, bar: number): number {
  console.log(this.name);
  return bar;
}

const bound = foo.bind({ name: 'baz' });

bound(2);

Screen Shot 2022-10-19 at 10 09 13 AM

type T = { name: string };

/**
 * @param bar number to return
 * @returns number returned back to caller
 */
function foo(this: T, bar: number): number {
  console.log(this.name);
  return bar;
}

const bound = foo.bind({ name: 'baz' });

bound(2);

Environment

  • Node version: 16
  • ESLint version 8.25.0
  • eslint-plugin-jsdoc version: 39.3.14

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions