Skip to content

Commit 1bbcb55

Browse files
authored
@typedef's nested Object syntax disallows type arguments (microsoft#36172)
Previously the jsdoc index signature syntax was incorrectly treated the same as Object: ```js /** @typedef {Object} AllowsNesting * @Property ... */ /** @typedef {Object.<string,string>} IncorrectlyAllowsNesting */ ``` Fixes microsoft#34911
1 parent 502e711 commit 1bbcb55

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7145,7 +7145,7 @@ namespace ts {
71457145
case SyntaxKind.ArrayType:
71467146
return isObjectOrObjectArrayTypeReference((node as ArrayTypeNode).elementType);
71477147
default:
7148-
return isTypeReferenceNode(node) && ts.isIdentifier(node.typeName) && node.typeName.escapedText === "Object";
7148+
return isTypeReferenceNode(node) && ts.isIdentifier(node.typeName) && node.typeName.escapedText === "Object" && !node.typeArguments;
71497149
}
71507150
}
71517151

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== tests/cases/conformance/jsdoc/typedefTagExtraneousProperty.js ===
2+
/** @typedef {Object.<string,string>} Mmap
3+
* @property {string} ignoreMe - should be ignored
4+
*/
5+
6+
/** @type {Mmap} */
7+
var y = { bye: "no" };
8+
>y : Symbol(y, Decl(typedefTagExtraneousProperty.js, 5, 3), Decl(typedefTagExtraneousProperty.js, 6, 1), Decl(typedefTagExtraneousProperty.js, 7, 57))
9+
>bye : Symbol(bye, Decl(typedefTagExtraneousProperty.js, 5, 9))
10+
11+
y
12+
>y : Symbol(y, Decl(typedefTagExtraneousProperty.js, 5, 3), Decl(typedefTagExtraneousProperty.js, 6, 1), Decl(typedefTagExtraneousProperty.js, 7, 57))
13+
14+
y.ignoreMe = "ok but just because of the index signature"
15+
>y : Symbol(y, Decl(typedefTagExtraneousProperty.js, 5, 3), Decl(typedefTagExtraneousProperty.js, 6, 1), Decl(typedefTagExtraneousProperty.js, 7, 57))
16+
17+
y['hi'] = "yes"
18+
>y : Symbol(y, Decl(typedefTagExtraneousProperty.js, 5, 3), Decl(typedefTagExtraneousProperty.js, 6, 1), Decl(typedefTagExtraneousProperty.js, 7, 57))
19+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/conformance/jsdoc/typedefTagExtraneousProperty.js ===
2+
/** @typedef {Object.<string,string>} Mmap
3+
* @property {string} ignoreMe - should be ignored
4+
*/
5+
6+
/** @type {Mmap} */
7+
var y = { bye: "no" };
8+
>y : { [x: string]: string; }
9+
>{ bye: "no" } : { bye: string; }
10+
>bye : string
11+
>"no" : "no"
12+
13+
y
14+
>y : { [x: string]: string; }
15+
16+
y.ignoreMe = "ok but just because of the index signature"
17+
>y.ignoreMe = "ok but just because of the index signature" : "ok but just because of the index signature"
18+
>y.ignoreMe : string
19+
>y : { [x: string]: string; }
20+
>ignoreMe : string
21+
>"ok but just because of the index signature" : "ok but just because of the index signature"
22+
23+
y['hi'] = "yes"
24+
>y['hi'] = "yes" : "yes"
25+
>y['hi'] : string
26+
>y : { [x: string]: string; }
27+
>'hi' : "hi"
28+
>"yes" : "yes"
29+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @lib: es5
2+
// @allowjs: true
3+
// @checkjs: true
4+
// @noemit: true
5+
// @Filename: typedefTagExtraneousProperty.js
6+
7+
/** @typedef {Object.<string,string>} Mmap
8+
* @property {string} ignoreMe - should be ignored
9+
*/
10+
11+
/** @type {Mmap} */
12+
var y = { bye: "no" };
13+
y
14+
y.ignoreMe = "ok but just because of the index signature"
15+
y['hi'] = "yes"

0 commit comments

Comments
 (0)