Skip to content

Commit 557a34e

Browse files
authored
Visit typedef type expressions so they contribute to referenced-ness (#23525)
1 parent 0526ff5 commit 557a34e

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21865,6 +21865,11 @@ namespace ts {
2186521865
// If the node had `@property` tags, `typeExpression` would have been set to the first property tag.
2186621866
error(node.name, Diagnostics.JSDoc_typedef_tag_should_either_have_a_type_annotation_or_be_followed_by_property_or_member_tags);
2186721867
}
21868+
21869+
if (node.name) {
21870+
checkTypeNameIsReserved(node.name, Diagnostics.Type_alias_name_cannot_be_0);
21871+
}
21872+
checkSourceElement(node.typeExpression);
2186821873
}
2186921874

2187021875
function checkJSDocParameterTag(node: JSDocParameterTag) {
@@ -24765,6 +24770,7 @@ namespace ts {
2476524770
case SyntaxKind.JSDocNullableType:
2476624771
case SyntaxKind.JSDocAllType:
2476724772
case SyntaxKind.JSDocUnknownType:
24773+
case SyntaxKind.JSDocTypeLiteral:
2476824774
checkJSDocTypeIsInJsFile(node);
2476924775
forEachChild(node, checkSourceElement);
2477024776
return;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
=== tests/cases/compiler/file.ts ===
2+
class Foo {
3+
>Foo : Symbol(Foo, Decl(file.ts, 0, 0))
4+
5+
x: number;
6+
>x : Symbol(Foo.x, Decl(file.ts, 0, 11))
7+
}
8+
9+
declare global {
10+
>global : Symbol(global, Decl(file.ts, 2, 1))
11+
12+
var module: any; // Just here to remove unrelated error from test
13+
>module : Symbol(module, Decl(file.ts, 5, 7))
14+
}
15+
16+
export = Foo;
17+
>Foo : Symbol(Foo, Decl(file.ts, 0, 0))
18+
19+
=== tests/cases/compiler/something.js ===
20+
/** @typedef {typeof import("./file")} Foo */
21+
22+
/** @typedef {(foo: Foo) => string} FooFun */
23+
24+
module.exports = /** @type {FooFun} */(void 0);
25+
>module : Symbol(export=, Decl(something.js, 0, 0))
26+
>exports : Symbol(export=, Decl(something.js, 0, 0))
27+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
=== tests/cases/compiler/file.ts ===
2+
class Foo {
3+
>Foo : Foo
4+
5+
x: number;
6+
>x : number
7+
}
8+
9+
declare global {
10+
>global : typeof global
11+
12+
var module: any; // Just here to remove unrelated error from test
13+
>module : any
14+
}
15+
16+
export = Foo;
17+
>Foo : Foo
18+
19+
=== tests/cases/compiler/something.js ===
20+
/** @typedef {typeof import("./file")} Foo */
21+
22+
/** @typedef {(foo: Foo) => string} FooFun */
23+
24+
module.exports = /** @type {FooFun} */(void 0);
25+
>module.exports = /** @type {FooFun} */(void 0) : (foo: typeof Foo) => string
26+
>module.exports : any
27+
>module : any
28+
>exports : any
29+
>(void 0) : (foo: typeof Foo) => string
30+
>void 0 : undefined
31+
>0 : 0
32+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
// @noUnusedLocals: true
5+
// @filename: file.ts
6+
class Foo {
7+
x: number;
8+
}
9+
10+
declare global {
11+
var module: any; // Just here to remove unrelated error from test
12+
}
13+
14+
export = Foo;
15+
// @filename: something.js
16+
/** @typedef {typeof import("./file")} Foo */
17+
18+
/** @typedef {(foo: Foo) => string} FooFun */
19+
20+
module.exports = /** @type {FooFun} */(void 0);

0 commit comments

Comments
 (0)