Skip to content

Commit d1be94b

Browse files
authored
fix(2157): jsdocfunction param is inferred as implicit any when directly assigned to module.exports (#2158)
1 parent 417387a commit d1be94b

File tree

93 files changed

+835
-1142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+835
-1142
lines changed

internal/fourslash/_scripts/failingTests.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ TestGetJavaScriptCompletions10
242242
TestGetJavaScriptCompletions12
243243
TestGetJavaScriptCompletions13
244244
TestGetJavaScriptCompletions15
245-
TestGetJavaScriptCompletions18
246245
TestGetJavaScriptCompletions20
247246
TestGetJavaScriptCompletions8
248247
TestGetJavaScriptCompletions9

internal/fourslash/tests/gen/getJavaScriptCompletions18_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func TestGetJavaScriptCompletions18(t *testing.T) {
1313
t.Parallel()
14-
t.Skip()
14+
1515
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1616
const content = `// @allowNonTsExtensions: true
1717
// @Filename: file.js

internal/parser/reparser.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,10 @@ func getFunctionLikeHost(host *ast.Node) (*ast.Node, bool) {
587587
fun = host.Expression()
588588
} else if host.Kind == ast.KindReturnStatement {
589589
fun = host.Expression()
590+
} else if host.Kind == ast.KindExpressionStatement {
591+
if ast.IsBinaryExpression(host.Expression()) {
592+
fun = host.Expression().AsBinaryExpression().Right
593+
}
590594
}
591595
if ast.IsFunctionLike(fun) {
592596
return fun, true

testdata/baselines/reference/submodule/compiler/jsDeclarationEmitExportAssignedFunctionWithExtraTypedefsMembers.errors.txt

Lines changed: 0 additions & 16 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/jsDeclarationEmitExportAssignedFunctionWithExtraTypedefsMembers.errors.txt.diff

Lines changed: 0 additions & 20 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/jsDeclarationEmitExportAssignedFunctionWithExtraTypedefsMembers.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,26 @@ module.exports = function loader(options) { };
3232
export type Options = {
3333
opt: string;
3434
};
35-
declare const _default: (options: any) => void;
35+
declare const _default: (options: Options) => void;
3636
export = _default;
37+
38+
39+
//// [DtsFileErrors]
40+
41+
42+
out/index.d.ts(9,1): error TS2309: An export assignment cannot be used in a module with other exported elements.
43+
44+
45+
==== out/index.d.ts (1 errors) ====
46+
/**
47+
* @typedef Options
48+
* @property {string} opt
49+
*/
50+
export type Options = {
51+
opt: string;
52+
};
53+
declare const _default: (options: Options) => void;
54+
export = _default;
55+
~~~~~~~~~~~~~~~~~~
56+
!!! error TS2309: An export assignment cannot be used in a module with other exported elements.
57+

testdata/baselines/reference/submodule/compiler/jsDeclarationEmitExportAssignedFunctionWithExtraTypedefsMembers.js.diff

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,26 @@
1717
+export type Options = {
1818
opt: string;
1919
};
20-
+declare const _default: (options: any) => void;
21-
+export = _default;
20+
+declare const _default: (options: Options) => void;
21+
+export = _default;
22+
+
23+
+
24+
+//// [DtsFileErrors]
25+
+
26+
+
27+
+out/index.d.ts(9,1): error TS2309: An export assignment cannot be used in a module with other exported elements.
28+
+
29+
+
30+
+==== out/index.d.ts (1 errors) ====
31+
+ /**
32+
+ * @typedef Options
33+
+ * @property {string} opt
34+
+ */
35+
+ export type Options = {
36+
+ opt: string;
37+
+ };
38+
+ declare const _default: (options: Options) => void;
39+
+ export = _default;
40+
+ ~~~~~~~~~~~~~~~~~~
41+
+!!! error TS2309: An export assignment cannot be used in a module with other exported elements.
42+
+

testdata/baselines/reference/submodule/compiler/jsDeclarationEmitExportAssignedFunctionWithExtraTypedefsMembers.types

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
* @param {Options} options
1111
*/
1212
module.exports = function loader(options) {}
13-
>module.exports = function loader(options) {} : (options: any) => void
14-
>module.exports : (options: any) => void
15-
>module : { "export=": (options: any) => void; }
16-
>exports : (options: any) => void
17-
>function loader(options) {} : (options: any) => void
18-
>loader : (options: any) => void
19-
>options : any
13+
>module.exports = function loader(options) {} : (options: Options) => void
14+
>module.exports : (options: Options) => void
15+
>module : { "export=": (options: Options) => void; }
16+
>exports : (options: Options) => void
17+
>function loader(options) {} : (options: Options) => void
18+
>loader : (options: Options) => void
19+
>options : Options
2020

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
--- old.jsDeclarationEmitExportAssignedFunctionWithExtraTypedefsMembers.types
22
+++ new.jsDeclarationEmitExportAssignedFunctionWithExtraTypedefsMembers.types
3-
@@= skipped -9, +9 lines =@@
4-
* @param {Options} options
5-
*/
3+
@@= skipped -11, +11 lines =@@
64
module.exports = function loader(options) {}
7-
->module.exports = function loader(options) {} : (options: Options) => void
8-
->module.exports : (options: Options) => void
5+
>module.exports = function loader(options) {} : (options: Options) => void
6+
>module.exports : (options: Options) => void
97
->module : { exports: (options: Options) => void; }
10-
->exports : (options: Options) => void
11-
->function loader(options) {} : (options: Options) => void
12-
->loader : (options: Options) => void
13-
->options : Options
14-
+>module.exports = function loader(options) {} : (options: any) => void
15-
+>module.exports : (options: any) => void
16-
+>module : { "export=": (options: any) => void; }
17-
+>exports : (options: any) => void
18-
+>function loader(options) {} : (options: any) => void
19-
+>loader : (options: any) => void
20-
+>options : any
8+
+>module : { "export=": (options: Options) => void; }
9+
>exports : (options: Options) => void
10+
>function loader(options) {} : (options: Options) => void
11+
>loader : (options: Options) => void

testdata/baselines/reference/submodule/compiler/jsElementAccessNoContextualTypeCrash.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
jsElementAccessNoContextualTypeCrash.js(2,1): error TS2322: Type '{ localize: (string: any) => any; } | {}' is not assignable to type '{ localize: (string: any) => any; }'.
2-
Property 'localize' is missing in type '{}' but required in type '{ localize: (string: any) => any; }'.
1+
jsElementAccessNoContextualTypeCrash.js(2,1): error TS2322: Type '{ localize: (string: string) => string; } | {}' is not assignable to type '{ localize: (string: string) => string; }'.
2+
Property 'localize' is missing in type '{}' but required in type '{ localize: (string: string) => string; }'.
33

44

55
==== jsElementAccessNoContextualTypeCrash.js (1 errors) ====
66
var Common = {};
77
self['Common'] = self['Common'] || {};
88
~~~~~~~~~~~~~~
9-
!!! error TS2322: Type '{ localize: (string: any) => any; } | {}' is not assignable to type '{ localize: (string: any) => any; }'.
10-
!!! error TS2322: Property 'localize' is missing in type '{}' but required in type '{ localize: (string: any) => any; }'.
9+
!!! error TS2322: Type '{ localize: (string: string) => string; } | {}' is not assignable to type '{ localize: (string: string) => string; }'.
10+
!!! error TS2322: Property 'localize' is missing in type '{}' but required in type '{ localize: (string: string) => string; }'.
1111
!!! related TS2728 jsElementAccessNoContextualTypeCrash.js:7:1: 'localize' is declared here.
1212
/**
1313
* @param {string} string

0 commit comments

Comments
 (0)