Skip to content

Commit 6524c31

Browse files
committed
fix(check-types): allow changing of Object in typescript mode; mentioned in gajus#800
1 parent 873228a commit 6524c31

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -5438,6 +5438,15 @@ function b () {}
54385438
*/
54395439
// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":["otherType","anotherType"]}}}}
54405440
// Message: Invalid JSDoc @aCustomTag "foo" type "Number"; prefer: ["otherType","anotherType"].
5441+
5442+
/**
5443+
* @param {Object[]} foo
5444+
*/
5445+
function quux (foo) {
5446+
5447+
}
5448+
// Settings: {"jsdoc":{"mode":"typescript","preferredTypes":{"Object":"object"}}}
5449+
// Message: Invalid JSDoc @param "foo" type "Object"; prefer: "object".
54415450
````
54425451

54435452
The following patterns are not considered problems:

src/rules/checkTypes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export default iterateJsdoc(({
221221
]);
222222
} else if (!noDefaults && type === 'JsdocTypeName') {
223223
for (const strictNativeType of strictNativeTypes) {
224-
if (strictNativeType === 'object' && mode === 'typescript') {
224+
if (strictNativeType === 'object' && mode === 'typescript' && !preferredTypes?.[nodeName]) {
225225
continue;
226226
}
227227

test/rules/assertions/checkTypes.js

+32
Original file line numberDiff line numberDiff line change
@@ -2129,6 +2129,38 @@ export default {
21292129
},
21302130
},
21312131
},
2132+
{
2133+
code: `
2134+
/**
2135+
* @param {Object[]} foo
2136+
*/
2137+
function quux (foo) {
2138+
2139+
}
2140+
`,
2141+
errors: [
2142+
{
2143+
line: 3,
2144+
message: 'Invalid JSDoc @param "foo" type "Object"; prefer: "object".',
2145+
},
2146+
],
2147+
output: `
2148+
/**
2149+
* @param {object[]} foo
2150+
*/
2151+
function quux (foo) {
2152+
2153+
}
2154+
`,
2155+
settings: {
2156+
jsdoc: {
2157+
mode: 'typescript',
2158+
preferredTypes: {
2159+
Object: 'object',
2160+
},
2161+
},
2162+
},
2163+
},
21322164
],
21332165
valid: [
21342166
{

0 commit comments

Comments
 (0)