Skip to content

Commit 9be846e

Browse files
author
Andy
authored
Fix bug when name resolution fails in a @typedef: Don't set lastLocation (microsoft#24585)
* Fix bug when name resolution fails in a @typedef: Don't set `lastLocation` * Add noEmit to test
1 parent a58054d commit 9be846e

File tree

5 files changed

+54
-3
lines changed

5 files changed

+54
-3
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,9 +1458,8 @@ namespace ts {
14581458
case SyntaxKind.JSDocTypedefTag:
14591459
case SyntaxKind.JSDocCallbackTag:
14601460
// js type aliases do not resolve names from their host, so skip past it
1461-
lastLocation = location;
1462-
location = getJSDocHost(location).parent;
1463-
continue;
1461+
location = getJSDocHost(location);
1462+
break;
14641463
}
14651464
if (isSelfReferenceLocation(location)) {
14661465
lastSelfReferenceLocation = location;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/a.js(7,14): error TS2304: Cannot find name 'CantResolveThis'.
2+
3+
4+
==== /a.js (1 errors) ====
5+
/**
6+
* @param {Ty} x
7+
*/
8+
function f(x) {}
9+
10+
/**
11+
* @typedef {CantResolveThis} Ty
12+
~~~~~~~~~~~~~~~
13+
!!! error TS2304: Cannot find name 'CantResolveThis'.
14+
*/
15+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== /a.js ===
2+
/**
3+
* @param {Ty} x
4+
*/
5+
function f(x) {}
6+
>f : Symbol(f, Decl(a.js, 0, 0))
7+
>x : Symbol(x, Decl(a.js, 3, 11))
8+
9+
/**
10+
* @typedef {CantResolveThis} Ty
11+
*/
12+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== /a.js ===
2+
/**
3+
* @param {Ty} x
4+
*/
5+
function f(x) {}
6+
>f : (x: any) => void
7+
>x : any
8+
9+
/**
10+
* @typedef {CantResolveThis} Ty
11+
*/
12+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
5+
// @Filename: /a.js
6+
/**
7+
* @param {Ty} x
8+
*/
9+
function f(x) {}
10+
11+
/**
12+
* @typedef {CantResolveThis} Ty
13+
*/

0 commit comments

Comments
 (0)