diff --git a/README.md b/README.md index 545d55e6a..b81e00ab1 100644 --- a/README.md +++ b/README.md @@ -9889,6 +9889,18 @@ function foo () { } // Settings: {"jsdoc":{"mode":"jsdoc"}} // Message: The type 'visibility' is undefined. + +/** +* @typedef Todo +* @property description +* @property otherStuff +*/ +/** + * @type {Omit} + */ +const a = new Todo(); +// Settings: {"jsdoc":{"mode":"jsdoc"}} +// Message: The type 'Omit' is undefined. ```` The following patterns are not considered problems: @@ -10302,6 +10314,17 @@ export class Foo { * @type {const} */ const a = 'string'; + +/** +* @typedef Todo +* @property description +* @property otherStuff +*/ +/** + * @type {Omit} + */ +const a = new Todo(); +// Settings: {"jsdoc":{"mode":"typescript"}} ```` diff --git a/src/rules/noUndefinedTypes.js b/src/rules/noUndefinedTypes.js index 98edef9db..77ba8d9d9 100644 --- a/src/rules/noUndefinedTypes.js +++ b/src/rules/noUndefinedTypes.js @@ -19,6 +19,30 @@ const extraTypes = [ 'Array', 'Object', 'RegExp', 'Date', 'Function', ]; +// https://www.typescriptlang.org/docs/handbook/utility-types.html +const typescriptGlobals = [ + 'Partial', + 'Required', + 'Readonly', + 'Record', + 'Pick', + 'Omit', + 'Exclude', + 'Extract', + 'NonNullable', + 'Parameters', + 'ConstructorParameters', + 'ReturnType', + 'InstanceType', + 'ThisParameterType', + 'OmitThisParameter', + 'ThisType', + 'Uppercase', + 'Lowercase', + 'Capitalize', + 'Uncapitalize', +]; + const stripPseudoTypes = (str) => { return str && str.replace(/(?:\.|<>|\.<>|\[\])$/u, ''); }; @@ -151,7 +175,14 @@ export default iterateJsdoc(({ .concat(typedefDeclarations) .concat(definedTypes) .concat(definedPreferredTypes) - .concat(settings.mode === 'jsdoc' ? [] : closureGenericTypes)); + .concat( + settings.mode === 'jsdoc' ? + [] : + [ + ...settings.mode === 'typescript' ? typescriptGlobals : [], + ...closureGenericTypes, + ], + )); const jsdocTagsWithPossibleType = utils.filterTags(({ tag, diff --git a/test/rules/assertions/noUndefinedTypes.js b/test/rules/assertions/noUndefinedTypes.js index 352d2f153..a2c48a376 100644 --- a/test/rules/assertions/noUndefinedTypes.js +++ b/test/rules/assertions/noUndefinedTypes.js @@ -460,6 +460,30 @@ export default { }, }, }, + { + code: ` + /** + * @typedef Todo + * @property description + * @property otherStuff + */ + /** + * @type {Omit} + */ + const a = new Todo(); + `, + errors: [ + { + line: 8, + message: 'The type \'Omit\' is undefined.', + }, + ], + settings: { + jsdoc: { + mode: 'jsdoc', + }, + }, + }, ], valid: [ { @@ -1216,5 +1240,23 @@ export default { const a = 'string'; `, }, + { + code: ` + /** + * @typedef Todo + * @property description + * @property otherStuff + */ + /** + * @type {Omit} + */ + const a = new Todo(); + `, + settings: { + jsdoc: { + mode: 'typescript', + }, + }, + }, ], };