diff --git a/.README/rules/no-undefined-types.md b/.README/rules/no-undefined-types.md index 2aca370c9..cd9714729 100644 --- a/.README/rules/no-undefined-types.md +++ b/.README/rules/no-undefined-types.md @@ -27,6 +27,7 @@ The following types are always considered defined. `function`, `symbol` - `number`, `bigint`, `NaN`, `Infinity` - `any`, `*` +- `this` - `Array`, `Object`, `RegExp`, `Date`, `Function` Note that preferred types indicated within `settings.jsdoc.preferredTypes` will diff --git a/README.md b/README.md index b0e977371..551e95973 100644 --- a/README.md +++ b/README.md @@ -7026,6 +7026,7 @@ The following types are always considered defined. `function`, `symbol` - `number`, `bigint`, `NaN`, `Infinity` - `any`, `*` +- `this` - `Array`, `Object`, `RegExp`, `Date`, `Function` Note that preferred types indicated within `settings.jsdoc.preferredTypes` will @@ -7563,6 +7564,17 @@ function quux () {} * @type {SomeType} */ // Settings: {"jsdoc":{"structuredTags":{"namepathDefiner":{"name":"namepath-defining"}}}} + +class Test { + /** + * Method. + * + * @returns {this} Return description. + */ + method (): this { + return this; + } +} ```` diff --git a/src/rules/noUndefinedTypes.js b/src/rules/noUndefinedTypes.js index acbbce4ff..d504ceafc 100644 --- a/src/rules/noUndefinedTypes.js +++ b/src/rules/noUndefinedTypes.js @@ -15,6 +15,7 @@ const extraTypes = [ 'function', 'symbol', 'number', 'bigint', 'NaN', 'Infinity', 'any', '*', + 'this', 'Array', 'Object', 'RegExp', 'Date', 'Function', ]; diff --git a/test/rules/assertions/noUndefinedTypes.js b/test/rules/assertions/noUndefinedTypes.js index e2ab3a784..bcf1acf13 100644 --- a/test/rules/assertions/noUndefinedTypes.js +++ b/test/rules/assertions/noUndefinedTypes.js @@ -938,5 +938,20 @@ export default { }, }, }, + { + code: ` + class Test { + /** + * Method. + * + * @returns {this} Return description. + */ + method (): this { + return this; + } + } + `, + parser: require.resolve('@typescript-eslint/parser'), + }, ], };