Skip to content

Commit ebfcc1b

Browse files
author
Andy
authored
Fix bug: Ignore @enum tag in TS (#27076)
1 parent 64d0e0d commit ebfcc1b

File tree

6 files changed

+33
-1
lines changed

6 files changed

+33
-1
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2666,7 +2666,7 @@ namespace ts {
26662666
}
26672667

26682668
if (!isBindingPattern(node.name)) {
2669-
const isEnum = !!getJSDocEnumTag(node);
2669+
const isEnum = isInJSFile(node) && !!getJSDocEnumTag(node);
26702670
const enumFlags = (isEnum ? SymbolFlags.RegularEnum : SymbolFlags.None);
26712671
const enumExcludes = (isEnum ? SymbolFlags.RegularEnumExcludes : SymbolFlags.None);
26722672
if (isBlockOrCatchScoped(node)) {

tests/baselines/reference/jsdocInTypeScript.errors.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,8 @@ tests/cases/compiler/jsdocInTypeScript.ts(42,12): error TS2503: Cannot find name
6767
* @type {{foo: (function(string, string): string)}}
6868
*/
6969
const obj = { foo: (a, b) => a + b };
70+
71+
/** @enum {string} */
72+
var E = {};
73+
E[""];
7074

tests/baselines/reference/jsdocInTypeScript.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ import M = N; // Error: @typedef does not create namespaces in TypeScript code.
4747
* @type {{foo: (function(string, string): string)}}
4848
*/
4949
const obj = { foo: (a, b) => a + b };
50+
51+
/** @enum {string} */
52+
var E = {};
53+
E[""];
5054

5155

5256
//// [jsdocInTypeScript.js]
@@ -79,3 +83,6 @@ var M = N; // Error: @typedef does not create namespaces in TypeScript code.
7983
* @type {{foo: (function(string, string): string)}}
8084
*/
8185
var obj = { foo: function (a, b) { return a + b; } };
86+
/** @enum {string} */
87+
var E = {};
88+
E[""];

tests/baselines/reference/jsdocInTypeScript.symbols

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,10 @@ const obj = { foo: (a, b) => a + b };
8383
>a : Symbol(a, Decl(jsdocInTypeScript.ts, 47, 20))
8484
>b : Symbol(b, Decl(jsdocInTypeScript.ts, 47, 22))
8585

86+
/** @enum {string} */
87+
var E = {};
88+
>E : Symbol(E, Decl(jsdocInTypeScript.ts, 50, 3))
89+
90+
E[""];
91+
>E : Symbol(E, Decl(jsdocInTypeScript.ts, 50, 3))
92+

tests/baselines/reference/jsdocInTypeScript.types

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,13 @@ const obj = { foo: (a, b) => a + b };
9393
>a : any
9494
>b : any
9595

96+
/** @enum {string} */
97+
var E = {};
98+
>E : {}
99+
>{} : {}
100+
101+
E[""];
102+
>E[""] : any
103+
>E : {}
104+
>"" : ""
105+

tests/cases/compiler/jsdocInTypeScript.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ import M = N; // Error: @typedef does not create namespaces in TypeScript code.
4646
* @type {{foo: (function(string, string): string)}}
4747
*/
4848
const obj = { foo: (a, b) => a + b };
49+
50+
/** @enum {string} */
51+
var E = {};
52+
E[""];

0 commit comments

Comments
 (0)