typescripteslintthis

ESLint disallow/ban `this` return type for verbosity


How do I use the ESLint no-restricted-syntax rule to disallow/ban the this keyword from being used as a return type on functions and class methods.


Solution

  • rules: {
        "no-restricted-syntax": [
            "error",
            "FunctionExpression[returnType.typeAnnotation.type='TSThisType']",
            "ArrowFunctionExpression[returnType.typeAnnotation.type='TSThisType']"
        ]
    }
    

    https://eslint.org/docs/v9.x/rules/no-restricted-syntax

    place of discovery