Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6807,7 +6807,7 @@ namespace ts {

// Record a new minimum argument count if this is not an optional parameter
const isOptionalParameter = param.initializer || param.questionToken || param.dotDotDotToken ||
iife && parameters.length > iife.arguments.length && !param.type ||
iife && parameters.length > iife.arguments.length && !param.type || param.type && param.type.kind === SyntaxKind.VoidKeyword ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A real fix here is quite a bit more involved, unfortunately.

This change doesn't fix the linked issue because it's only looking for the exact syntactic form of function f(x: void) (which no one would write) instead of actually detecting the type of the parameter during overload resolution and treating it as optional.

isJSDocOptionalParameter(param) ||
isUntypedSignatureInJSFile;
if (!isOptionalParameter) {
Expand Down
57 changes: 57 additions & 0 deletions tests/baselines/reference/functionCallWithVoidParameter.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
tests/cases/conformance/functions/functionCallWithVoidParameter.ts(17,1): error TS2554: Expected 1-2 arguments, but got 0.
tests/cases/conformance/functions/functionCallWithVoidParameter.ts(22,1): error TS2554: Expected 2 arguments, but got 0.
tests/cases/conformance/functions/functionCallWithVoidParameter.ts(23,1): error TS2554: Expected 2 arguments, but got 1.
tests/cases/conformance/functions/functionCallWithVoidParameter.ts(24,1): error TS2554: Expected 2 arguments, but got 1.
tests/cases/conformance/functions/functionCallWithVoidParameter.ts(29,1): error TS2554: Expected 2 arguments, but got 0.
tests/cases/conformance/functions/functionCallWithVoidParameter.ts(30,1): error TS2554: Expected 2 arguments, but got 1.


==== tests/cases/conformance/functions/functionCallWithVoidParameter.ts (6 errors) ====
function f1 (a: number, b: void) { }
function f2 (a: void) { }
function f3 (a: void, b: number) { }
function f4 (a: number | void) { }
function f5 (a: number | void, b: void) { }
function f6 (a: number | void, b: number | void) { }
function f7 (a: void, b: number | void) { }
function f8 (a: void, b: void) { }

f1(1);
f1(1, void 0);
f2();
f2(void 0);
f3(void 0, 1);
f4(1);
f4(void 0);
f5()
~~~~
!!! error TS2554: Expected 1-2 arguments, but got 0.
f5(1)
f5(1, void 0);
f5(void 0, void 0);
f5(void 0);
f6();
~~~~
!!! error TS2554: Expected 2 arguments, but got 0.
f6(1);
~~~~~
!!! error TS2554: Expected 2 arguments, but got 1.
f6(void 0);
~~~~~~~~~~
!!! error TS2554: Expected 2 arguments, but got 1.
f6(1, 1);
f6(1, void 0);
f6(void 0, void 0);
f6(void 0, 1);
f7();
~~~~
!!! error TS2554: Expected 2 arguments, but got 0.
f7(void 0);
~~~~~~~~~~
!!! error TS2554: Expected 2 arguments, but got 1.
f7(void 0, 1);
f7(void 0, void 0);
f8();
f8(void 0);
f8(void 0, void 0);

73 changes: 73 additions & 0 deletions tests/baselines/reference/functionCallWithVoidParameter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//// [functionCallWithVoidParameter.ts]
function f1 (a: number, b: void) { }
function f2 (a: void) { }
function f3 (a: void, b: number) { }
function f4 (a: number | void) { }
function f5 (a: number | void, b: void) { }
function f6 (a: number | void, b: number | void) { }
function f7 (a: void, b: number | void) { }
function f8 (a: void, b: void) { }

f1(1);
f1(1, void 0);
f2();
f2(void 0);
f3(void 0, 1);
f4(1);
f4(void 0);
f5()
f5(1)
f5(1, void 0);
f5(void 0, void 0);
f5(void 0);
f6();
f6(1);
f6(void 0);
f6(1, 1);
f6(1, void 0);
f6(void 0, void 0);
f6(void 0, 1);
f7();
f7(void 0);
f7(void 0, 1);
f7(void 0, void 0);
f8();
f8(void 0);
f8(void 0, void 0);


//// [functionCallWithVoidParameter.js]
function f1(a, b) { }
function f2(a) { }
function f3(a, b) { }
function f4(a) { }
function f5(a, b) { }
function f6(a, b) { }
function f7(a, b) { }
function f8(a, b) { }
f1(1);
f1(1, void 0);
f2();
f2(void 0);
f3(void 0, 1);
f4(1);
f4(void 0);
f5();
f5(1);
f5(1, void 0);
f5(void 0, void 0);
f5(void 0);
f6();
f6(1);
f6(void 0);
f6(1, 1);
f6(1, void 0);
f6(void 0, void 0);
f6(void 0, 1);
f7();
f7(void 0);
f7(void 0, 1);
f7(void 0, void 0);
f8();
f8(void 0);
f8(void 0, void 0);
117 changes: 117 additions & 0 deletions tests/baselines/reference/functionCallWithVoidParameter.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
=== tests/cases/conformance/functions/functionCallWithVoidParameter.ts ===
function f1 (a: number, b: void) { }
>f1 : Symbol(f1, Decl(functionCallWithVoidParameter.ts, 0, 0))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 0, 13))
>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 0, 23))

function f2 (a: void) { }
>f2 : Symbol(f2, Decl(functionCallWithVoidParameter.ts, 0, 36))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 1, 13))

function f3 (a: void, b: number) { }
>f3 : Symbol(f3, Decl(functionCallWithVoidParameter.ts, 1, 25))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 2, 13))
>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 2, 21))

function f4 (a: number | void) { }
>f4 : Symbol(f4, Decl(functionCallWithVoidParameter.ts, 2, 36))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 3, 13))

function f5 (a: number | void, b: void) { }
>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 34))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 4, 13))
>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 4, 30))

function f6 (a: number | void, b: number | void) { }
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 5, 13))
>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 5, 30))

function f7 (a: void, b: number | void) { }
>f7 : Symbol(f7, Decl(functionCallWithVoidParameter.ts, 5, 52))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 6, 13))
>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 6, 21))

function f8 (a: void, b: void) { }
>f8 : Symbol(f8, Decl(functionCallWithVoidParameter.ts, 6, 43))
>a : Symbol(a, Decl(functionCallWithVoidParameter.ts, 7, 13))
>b : Symbol(b, Decl(functionCallWithVoidParameter.ts, 7, 21))

f1(1);
>f1 : Symbol(f1, Decl(functionCallWithVoidParameter.ts, 0, 0))

f1(1, void 0);
>f1 : Symbol(f1, Decl(functionCallWithVoidParameter.ts, 0, 0))

f2();
>f2 : Symbol(f2, Decl(functionCallWithVoidParameter.ts, 0, 36))

f2(void 0);
>f2 : Symbol(f2, Decl(functionCallWithVoidParameter.ts, 0, 36))

f3(void 0, 1);
>f3 : Symbol(f3, Decl(functionCallWithVoidParameter.ts, 1, 25))

f4(1);
>f4 : Symbol(f4, Decl(functionCallWithVoidParameter.ts, 2, 36))

f4(void 0);
>f4 : Symbol(f4, Decl(functionCallWithVoidParameter.ts, 2, 36))

f5()
>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 34))

f5(1)
>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 34))

f5(1, void 0);
>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 34))

f5(void 0, void 0);
>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 34))

f5(void 0);
>f5 : Symbol(f5, Decl(functionCallWithVoidParameter.ts, 3, 34))

f6();
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43))

f6(1);
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43))

f6(void 0);
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43))

f6(1, 1);
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43))

f6(1, void 0);
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43))

f6(void 0, void 0);
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43))

f6(void 0, 1);
>f6 : Symbol(f6, Decl(functionCallWithVoidParameter.ts, 4, 43))

f7();
>f7 : Symbol(f7, Decl(functionCallWithVoidParameter.ts, 5, 52))

f7(void 0);
>f7 : Symbol(f7, Decl(functionCallWithVoidParameter.ts, 5, 52))

f7(void 0, 1);
>f7 : Symbol(f7, Decl(functionCallWithVoidParameter.ts, 5, 52))

f7(void 0, void 0);
>f7 : Symbol(f7, Decl(functionCallWithVoidParameter.ts, 5, 52))

f8();
>f8 : Symbol(f8, Decl(functionCallWithVoidParameter.ts, 6, 43))

f8(void 0);
>f8 : Symbol(f8, Decl(functionCallWithVoidParameter.ts, 6, 43))

f8(void 0, void 0);
>f8 : Symbol(f8, Decl(functionCallWithVoidParameter.ts, 6, 43))

Loading