From b66321a2772a4652efe539ecd8f7dd81fc1f8058 Mon Sep 17 00:00:00 2001 From: Jack Williams Date: Thu, 13 Sep 2018 23:42:06 +0100 Subject: [PATCH 1/3] Allow arguments that accept void to be omitted --- src/compiler/checker.ts | 14 +- .../reference/callWithMissingVoid.errors.txt | 131 ++++++++ .../reference/callWithMissingVoid.js | 135 ++++++++ .../reference/callWithMissingVoid.symbols | 218 +++++++++++++ .../reference/callWithMissingVoid.types | 296 ++++++++++++++++++ .../functionCalls/callWithMissingVoid.ts | 82 +++++ 6 files changed, 874 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/callWithMissingVoid.errors.txt create mode 100644 tests/baselines/reference/callWithMissingVoid.js create mode 100644 tests/baselines/reference/callWithMissingVoid.symbols create mode 100644 tests/baselines/reference/callWithMissingVoid.types create mode 100644 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6f541461b092c..adebd1c67048d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18900,8 +18900,18 @@ namespace ts { } // If the call is incomplete, we should skip the lower bound check. - const hasEnoughArguments = argCount >= getMinArgumentCount(signature); - return callIsIncomplete || hasEnoughArguments; + const minArgs = getMinArgumentCount(signature); + if (callIsIncomplete || argCount >= minArgs) { + return true; + } + const acceptsVoid = (t: Type): boolean => !!(t.flags & TypeFlags.Void); + for (let i = argCount; i < minArgs; i++) { + const type = getTypeAtPosition(signature, i); + if (filterType(type, acceptsVoid).flags & TypeFlags.Never) { + return false; + } + } + return true; } function hasCorrectTypeArgumentArity(signature: Signature, typeArguments: NodeArray | undefined) { diff --git a/tests/baselines/reference/callWithMissingVoid.errors.txt b/tests/baselines/reference/callWithMissingVoid.errors.txt new file mode 100644 index 0000000000000..c37ea69b5e8cb --- /dev/null +++ b/tests/baselines/reference/callWithMissingVoid.errors.txt @@ -0,0 +1,131 @@ +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(16,1): error TS2554: Expected 1 arguments, but got 0. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(19,1): error TS2554: Expected 1 arguments, but got 0. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(32,31): error TS2554: Expected 1 arguments, but got 0. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(33,35): error TS2554: Expected 1 arguments, but got 0. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(44,1): error TS2554: Expected 3 arguments, but got 1. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(51,1): error TS2554: Expected 4 arguments, but got 2. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(52,1): error TS2554: Expected 4 arguments, but got 3. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(53,1): error TS2554: Expected 4 arguments, but got 1. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(71,6): error TS2345: Argument of type '(x: number, y: number) => number' is not assignable to parameter of type '() => void'. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(75,6): error TS2345: Argument of type '(x: number, y: void) => number' is not assignable to parameter of type '(args_0: number) => void'. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(76,6): error TS2345: Argument of type '(x: void, y: void) => number' is not assignable to parameter of type '() => void'. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(77,6): error TS2345: Argument of type '(x: number | void, y: number | void) => number' is not assignable to parameter of type '() => void'. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(78,6): error TS2345: Argument of type '(x: number | void, y: number | void) => number' is not assignable to parameter of type '(args_0: number) => void'. + + +==== tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts (13 errors) ==== + // From #4260 + class X { + f(t: T) { + return { a: t }; + } + } + + declare const x: X; + x.f() // no error because f expects void + + declare const xUnion: X; + xUnion.f(42) // no error because f accepts number + xUnion.f() // no error because f accepts void + + declare const xAny: X; + xAny.f() // error, any still expects an argument + ~~~~~~~~ +!!! error TS2554: Expected 1 arguments, but got 0. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:3:7: An argument for 't' was not provided. + + declare const xUnknown: X; + xUnknown.f() // error, unknown still expects an argument + ~~~~~~~~~~~~ +!!! error TS2554: Expected 1 arguments, but got 0. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:3:7: An argument for 't' was not provided. + + + // Promise has previously been updated to work without arguments, but to show this fixes the issue too. + + class MyPromise { + constructor(executor: (resolve: (value: X) => void) => void) { + + } + } + + new MyPromise(resolve => resolve()); // no error + new MyPromise(resolve => resolve()); // no error + new MyPromise(resolve => resolve()); // error, `any` arguments cannot be omitted + ~~~~~~~~~ +!!! error TS2554: Expected 1 arguments, but got 0. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:25:38: An argument for 'value' was not provided. + new MyPromise(resolve => resolve()); // error, `unknown` arguments cannot be omitted + ~~~~~~~~~ +!!! error TS2554: Expected 1 arguments, but got 0. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:25:38: An argument for 'value' was not provided. + + + // Multiple parameters + + function a(x: number, y: string, z: void): void { + + } + + a(4, "hello"); // ok + a(4, "hello", void 0); // ok + a(4); // not ok + ~~~~ +!!! error TS2554: Expected 3 arguments, but got 1. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:38:23: An argument for 'y' was not provided. + + function b(x: number, y: string, z: void, what: number): void { + + } + + b(4, "hello", void 0, 2); // ok + b(4, "hello"); // not ok + ~~~~~~~~~~~~~ +!!! error TS2554: Expected 4 arguments, but got 2. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:46:34: An argument for 'z' was not provided. + b(4, "hello", void 0); // not ok + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2554: Expected 4 arguments, but got 3. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:46:43: An argument for 'what' was not provided. + b(4); // not ok + ~~~~ +!!! error TS2554: Expected 4 arguments, but got 1. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:46:23: An argument for 'y' was not provided. + + function c(x: number | void, y: void, z: void | string | number): void { + + } + + c(3, void 0, void 0); // ok + c(3, void 0); // ok + c(3); // ok + c(); // ok + + + // Spread Parameters + + declare function call( + handler: (...args: TS) => void, + ...args: TS): void; + + call((x: number, y: number) => x + y) // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number, y: number) => number' is not assignable to parameter of type '() => void'. + call((x: number, y: number) => x + y, 4, 2) // ok + + call((x: number, y: void) => x, 4, void 0) // ok + call((x: number, y: void) => x, 4) // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number, y: void) => number' is not assignable to parameter of type '(args_0: number) => void'. + call((x: void, y: void) => 42) // ok + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: void, y: void) => number' is not assignable to parameter of type '() => void'. + call((x: number | void, y: number | void) => 42) // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number | void, y: number | void) => number' is not assignable to parameter of type '() => void'. + call((x: number | void, y: number | void) => 42, 4) // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number | void, y: number | void) => number' is not assignable to parameter of type '(args_0: number) => void'. + call((x: number | void, y: number | void) => 42, 4, 2) // ok + + \ No newline at end of file diff --git a/tests/baselines/reference/callWithMissingVoid.js b/tests/baselines/reference/callWithMissingVoid.js new file mode 100644 index 0000000000000..4437053298706 --- /dev/null +++ b/tests/baselines/reference/callWithMissingVoid.js @@ -0,0 +1,135 @@ +//// [callWithMissingVoid.ts] +// From #4260 +class X { + f(t: T) { + return { a: t }; + } +} + +declare const x: X; +x.f() // no error because f expects void + +declare const xUnion: X; +xUnion.f(42) // no error because f accepts number +xUnion.f() // no error because f accepts void + +declare const xAny: X; +xAny.f() // error, any still expects an argument + +declare const xUnknown: X; +xUnknown.f() // error, unknown still expects an argument + + +// Promise has previously been updated to work without arguments, but to show this fixes the issue too. + +class MyPromise { + constructor(executor: (resolve: (value: X) => void) => void) { + + } +} + +new MyPromise(resolve => resolve()); // no error +new MyPromise(resolve => resolve()); // no error +new MyPromise(resolve => resolve()); // error, `any` arguments cannot be omitted +new MyPromise(resolve => resolve()); // error, `unknown` arguments cannot be omitted + + +// Multiple parameters + +function a(x: number, y: string, z: void): void { + +} + +a(4, "hello"); // ok +a(4, "hello", void 0); // ok +a(4); // not ok + +function b(x: number, y: string, z: void, what: number): void { + +} + +b(4, "hello", void 0, 2); // ok +b(4, "hello"); // not ok +b(4, "hello", void 0); // not ok +b(4); // not ok + +function c(x: number | void, y: void, z: void | string | number): void { + +} + +c(3, void 0, void 0); // ok +c(3, void 0); // ok +c(3); // ok +c(); // ok + + +// Spread Parameters + +declare function call( + handler: (...args: TS) => void, + ...args: TS): void; + +call((x: number, y: number) => x + y) // error +call((x: number, y: number) => x + y, 4, 2) // ok + +call((x: number, y: void) => x, 4, void 0) // ok +call((x: number, y: void) => x, 4) // ok +call((x: void, y: void) => 42) // ok +call((x: number | void, y: number | void) => 42) // ok +call((x: number | void, y: number | void) => 42, 4) // ok +call((x: number | void, y: number | void) => 42, 4, 2) // ok + + + +//// [callWithMissingVoid.js] +"use strict"; +// From #4260 +var X = /** @class */ (function () { + function X() { + } + X.prototype.f = function (t) { + return { a: t }; + }; + return X; +}()); +x.f(); // no error because f expects void +xUnion.f(42); // no error because f accepts number +xUnion.f(); // no error because f accepts void +xAny.f(); // error, any still expects an argument +xUnknown.f(); // error, unknown still expects an argument +// Promise has previously been updated to work without arguments, but to show this fixes the issue too. +var MyPromise = /** @class */ (function () { + function MyPromise(executor) { + } + return MyPromise; +}()); +new MyPromise(function (resolve) { return resolve(); }); // no error +new MyPromise(function (resolve) { return resolve(); }); // no error +new MyPromise(function (resolve) { return resolve(); }); // error, `any` arguments cannot be omitted +new MyPromise(function (resolve) { return resolve(); }); // error, `unknown` arguments cannot be omitted +// Multiple parameters +function a(x, y, z) { +} +a(4, "hello"); // ok +a(4, "hello", void 0); // ok +a(4); // not ok +function b(x, y, z, what) { +} +b(4, "hello", void 0, 2); // ok +b(4, "hello"); // not ok +b(4, "hello", void 0); // not ok +b(4); // not ok +function c(x, y, z) { +} +c(3, void 0, void 0); // ok +c(3, void 0); // ok +c(3); // ok +c(); // ok +call(function (x, y) { return x + y; }); // error +call(function (x, y) { return x + y; }, 4, 2); // ok +call(function (x, y) { return x; }, 4, void 0); // ok +call(function (x, y) { return x; }, 4); // ok +call(function (x, y) { return 42; }); // ok +call(function (x, y) { return 42; }); // ok +call(function (x, y) { return 42; }, 4); // ok +call(function (x, y) { return 42; }, 4, 2); // ok diff --git a/tests/baselines/reference/callWithMissingVoid.symbols b/tests/baselines/reference/callWithMissingVoid.symbols new file mode 100644 index 0000000000000..f5c7b741023ae --- /dev/null +++ b/tests/baselines/reference/callWithMissingVoid.symbols @@ -0,0 +1,218 @@ +=== tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts === +// From #4260 +class X { +>X : Symbol(X, Decl(callWithMissingVoid.ts, 0, 0)) +>T : Symbol(T, Decl(callWithMissingVoid.ts, 1, 8)) + + f(t: T) { +>f : Symbol(X.f, Decl(callWithMissingVoid.ts, 1, 12)) +>t : Symbol(t, Decl(callWithMissingVoid.ts, 2, 6)) +>T : Symbol(T, Decl(callWithMissingVoid.ts, 1, 8)) + + return { a: t }; +>a : Symbol(a, Decl(callWithMissingVoid.ts, 3, 16)) +>t : Symbol(t, Decl(callWithMissingVoid.ts, 2, 6)) + } +} + +declare const x: X; +>x : Symbol(x, Decl(callWithMissingVoid.ts, 7, 13)) +>X : Symbol(X, Decl(callWithMissingVoid.ts, 0, 0)) + +x.f() // no error because f expects void +>x.f : Symbol(X.f, Decl(callWithMissingVoid.ts, 1, 12)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 7, 13)) +>f : Symbol(X.f, Decl(callWithMissingVoid.ts, 1, 12)) + +declare const xUnion: X; +>xUnion : Symbol(xUnion, Decl(callWithMissingVoid.ts, 10, 13)) +>X : Symbol(X, Decl(callWithMissingVoid.ts, 0, 0)) + +xUnion.f(42) // no error because f accepts number +>xUnion.f : Symbol(X.f, Decl(callWithMissingVoid.ts, 1, 12)) +>xUnion : Symbol(xUnion, Decl(callWithMissingVoid.ts, 10, 13)) +>f : Symbol(X.f, Decl(callWithMissingVoid.ts, 1, 12)) + +xUnion.f() // no error because f accepts void +>xUnion.f : Symbol(X.f, Decl(callWithMissingVoid.ts, 1, 12)) +>xUnion : Symbol(xUnion, Decl(callWithMissingVoid.ts, 10, 13)) +>f : Symbol(X.f, Decl(callWithMissingVoid.ts, 1, 12)) + +declare const xAny: X; +>xAny : Symbol(xAny, Decl(callWithMissingVoid.ts, 14, 13)) +>X : Symbol(X, Decl(callWithMissingVoid.ts, 0, 0)) + +xAny.f() // error, any still expects an argument +>xAny.f : Symbol(X.f, Decl(callWithMissingVoid.ts, 1, 12)) +>xAny : Symbol(xAny, Decl(callWithMissingVoid.ts, 14, 13)) +>f : Symbol(X.f, Decl(callWithMissingVoid.ts, 1, 12)) + +declare const xUnknown: X; +>xUnknown : Symbol(xUnknown, Decl(callWithMissingVoid.ts, 17, 13)) +>X : Symbol(X, Decl(callWithMissingVoid.ts, 0, 0)) + +xUnknown.f() // error, unknown still expects an argument +>xUnknown.f : Symbol(X.f, Decl(callWithMissingVoid.ts, 1, 12)) +>xUnknown : Symbol(xUnknown, Decl(callWithMissingVoid.ts, 17, 13)) +>f : Symbol(X.f, Decl(callWithMissingVoid.ts, 1, 12)) + + +// Promise has previously been updated to work without arguments, but to show this fixes the issue too. + +class MyPromise { +>MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 18, 12)) +>X : Symbol(X, Decl(callWithMissingVoid.ts, 23, 16)) + + constructor(executor: (resolve: (value: X) => void) => void) { +>executor : Symbol(executor, Decl(callWithMissingVoid.ts, 24, 16)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 24, 27)) +>value : Symbol(value, Decl(callWithMissingVoid.ts, 24, 37)) +>X : Symbol(X, Decl(callWithMissingVoid.ts, 23, 16)) + + } +} + +new MyPromise(resolve => resolve()); // no error +>MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 18, 12)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 29, 20)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 29, 20)) + +new MyPromise(resolve => resolve()); // no error +>MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 18, 12)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 30, 29)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 30, 29)) + +new MyPromise(resolve => resolve()); // error, `any` arguments cannot be omitted +>MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 18, 12)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 31, 19)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 31, 19)) + +new MyPromise(resolve => resolve()); // error, `unknown` arguments cannot be omitted +>MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 18, 12)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 32, 23)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 32, 23)) + + +// Multiple parameters + +function a(x: number, y: string, z: void): void { +>a : Symbol(a, Decl(callWithMissingVoid.ts, 32, 45)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 37, 11)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 37, 21)) +>z : Symbol(z, Decl(callWithMissingVoid.ts, 37, 32)) + +} + +a(4, "hello"); // ok +>a : Symbol(a, Decl(callWithMissingVoid.ts, 32, 45)) + +a(4, "hello", void 0); // ok +>a : Symbol(a, Decl(callWithMissingVoid.ts, 32, 45)) + +a(4); // not ok +>a : Symbol(a, Decl(callWithMissingVoid.ts, 32, 45)) + +function b(x: number, y: string, z: void, what: number): void { +>b : Symbol(b, Decl(callWithMissingVoid.ts, 43, 5)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 45, 11)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 45, 21)) +>z : Symbol(z, Decl(callWithMissingVoid.ts, 45, 32)) +>what : Symbol(what, Decl(callWithMissingVoid.ts, 45, 41)) + +} + +b(4, "hello", void 0, 2); // ok +>b : Symbol(b, Decl(callWithMissingVoid.ts, 43, 5)) + +b(4, "hello"); // not ok +>b : Symbol(b, Decl(callWithMissingVoid.ts, 43, 5)) + +b(4, "hello", void 0); // not ok +>b : Symbol(b, Decl(callWithMissingVoid.ts, 43, 5)) + +b(4); // not ok +>b : Symbol(b, Decl(callWithMissingVoid.ts, 43, 5)) + +function c(x: number | void, y: void, z: void | string | number): void { +>c : Symbol(c, Decl(callWithMissingVoid.ts, 52, 5)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 54, 11)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 54, 28)) +>z : Symbol(z, Decl(callWithMissingVoid.ts, 54, 37)) + +} + +c(3, void 0, void 0); // ok +>c : Symbol(c, Decl(callWithMissingVoid.ts, 52, 5)) + +c(3, void 0); // ok +>c : Symbol(c, Decl(callWithMissingVoid.ts, 52, 5)) + +c(3); // ok +>c : Symbol(c, Decl(callWithMissingVoid.ts, 52, 5)) + +c(); // ok +>c : Symbol(c, Decl(callWithMissingVoid.ts, 52, 5)) + + +// Spread Parameters + +declare function call( +>call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) +>TS : Symbol(TS, Decl(callWithMissingVoid.ts, 66, 22)) + + handler: (...args: TS) => void, +>handler : Symbol(handler, Decl(callWithMissingVoid.ts, 66, 44)) +>args : Symbol(args, Decl(callWithMissingVoid.ts, 67, 14)) +>TS : Symbol(TS, Decl(callWithMissingVoid.ts, 66, 22)) + + ...args: TS): void; +>args : Symbol(args, Decl(callWithMissingVoid.ts, 67, 35)) +>TS : Symbol(TS, Decl(callWithMissingVoid.ts, 66, 22)) + +call((x: number, y: number) => x + y) // error +>call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 70, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 70, 16)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 70, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 70, 16)) + +call((x: number, y: number) => x + y, 4, 2) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 71, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 71, 16)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 71, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 71, 16)) + +call((x: number, y: void) => x, 4, void 0) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 73, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 73, 16)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 73, 6)) + +call((x: number, y: void) => x, 4) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 74, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 74, 16)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 74, 6)) + +call((x: void, y: void) => 42) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 75, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 75, 14)) + +call((x: number | void, y: number | void) => 42) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 76, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 76, 23)) + +call((x: number | void, y: number | void) => 42, 4) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 77, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 77, 23)) + +call((x: number | void, y: number | void) => 42, 4, 2) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 78, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 78, 23)) + + diff --git a/tests/baselines/reference/callWithMissingVoid.types b/tests/baselines/reference/callWithMissingVoid.types new file mode 100644 index 0000000000000..6a2b74c379455 --- /dev/null +++ b/tests/baselines/reference/callWithMissingVoid.types @@ -0,0 +1,296 @@ +=== tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts === +// From #4260 +class X { +>X : X + + f(t: T) { +>f : (t: T) => { a: T; } +>t : T + + return { a: t }; +>{ a: t } : { a: T; } +>a : T +>t : T + } +} + +declare const x: X; +>x : X + +x.f() // no error because f expects void +>x.f() : { a: void; } +>x.f : (t: void) => { a: void; } +>x : X +>f : (t: void) => { a: void; } + +declare const xUnion: X; +>xUnion : X + +xUnion.f(42) // no error because f accepts number +>xUnion.f(42) : { a: number | void; } +>xUnion.f : (t: number | void) => { a: number | void; } +>xUnion : X +>f : (t: number | void) => { a: number | void; } +>42 : 42 + +xUnion.f() // no error because f accepts void +>xUnion.f() : { a: number | void; } +>xUnion.f : (t: number | void) => { a: number | void; } +>xUnion : X +>f : (t: number | void) => { a: number | void; } + +declare const xAny: X; +>xAny : X + +xAny.f() // error, any still expects an argument +>xAny.f() : { a: any; } +>xAny.f : (t: any) => { a: any; } +>xAny : X +>f : (t: any) => { a: any; } + +declare const xUnknown: X; +>xUnknown : X + +xUnknown.f() // error, unknown still expects an argument +>xUnknown.f() : { a: unknown; } +>xUnknown.f : (t: unknown) => { a: unknown; } +>xUnknown : X +>f : (t: unknown) => { a: unknown; } + + +// Promise has previously been updated to work without arguments, but to show this fixes the issue too. + +class MyPromise { +>MyPromise : MyPromise + + constructor(executor: (resolve: (value: X) => void) => void) { +>executor : (resolve: (value: X) => void) => void +>resolve : (value: X) => void +>value : X + + } +} + +new MyPromise(resolve => resolve()); // no error +>new MyPromise(resolve => resolve()) : MyPromise +>MyPromise : typeof MyPromise +>resolve => resolve() : (resolve: (value: void) => void) => void +>resolve : (value: void) => void +>resolve() : void +>resolve : (value: void) => void + +new MyPromise(resolve => resolve()); // no error +>new MyPromise(resolve => resolve()) : MyPromise +>MyPromise : typeof MyPromise +>resolve => resolve() : (resolve: (value: number | void) => void) => void +>resolve : (value: number | void) => void +>resolve() : void +>resolve : (value: number | void) => void + +new MyPromise(resolve => resolve()); // error, `any` arguments cannot be omitted +>new MyPromise(resolve => resolve()) : MyPromise +>MyPromise : typeof MyPromise +>resolve => resolve() : (resolve: (value: any) => void) => any +>resolve : (value: any) => void +>resolve() : void +>resolve : (value: any) => void + +new MyPromise(resolve => resolve()); // error, `unknown` arguments cannot be omitted +>new MyPromise(resolve => resolve()) : MyPromise +>MyPromise : typeof MyPromise +>resolve => resolve() : (resolve: (value: unknown) => void) => any +>resolve : (value: unknown) => void +>resolve() : void +>resolve : (value: unknown) => void + + +// Multiple parameters + +function a(x: number, y: string, z: void): void { +>a : (x: number, y: string, z: void) => void +>x : number +>y : string +>z : void + +} + +a(4, "hello"); // ok +>a(4, "hello") : void +>a : (x: number, y: string, z: void) => void +>4 : 4 +>"hello" : "hello" + +a(4, "hello", void 0); // ok +>a(4, "hello", void 0) : void +>a : (x: number, y: string, z: void) => void +>4 : 4 +>"hello" : "hello" +>void 0 : undefined +>0 : 0 + +a(4); // not ok +>a(4) : void +>a : (x: number, y: string, z: void) => void +>4 : 4 + +function b(x: number, y: string, z: void, what: number): void { +>b : (x: number, y: string, z: void, what: number) => void +>x : number +>y : string +>z : void +>what : number + +} + +b(4, "hello", void 0, 2); // ok +>b(4, "hello", void 0, 2) : void +>b : (x: number, y: string, z: void, what: number) => void +>4 : 4 +>"hello" : "hello" +>void 0 : undefined +>0 : 0 +>2 : 2 + +b(4, "hello"); // not ok +>b(4, "hello") : void +>b : (x: number, y: string, z: void, what: number) => void +>4 : 4 +>"hello" : "hello" + +b(4, "hello", void 0); // not ok +>b(4, "hello", void 0) : void +>b : (x: number, y: string, z: void, what: number) => void +>4 : 4 +>"hello" : "hello" +>void 0 : undefined +>0 : 0 + +b(4); // not ok +>b(4) : void +>b : (x: number, y: string, z: void, what: number) => void +>4 : 4 + +function c(x: number | void, y: void, z: void | string | number): void { +>c : (x: number | void, y: void, z: string | number | void) => void +>x : number | void +>y : void +>z : string | number | void + +} + +c(3, void 0, void 0); // ok +>c(3, void 0, void 0) : void +>c : (x: number | void, y: void, z: string | number | void) => void +>3 : 3 +>void 0 : undefined +>0 : 0 +>void 0 : undefined +>0 : 0 + +c(3, void 0); // ok +>c(3, void 0) : void +>c : (x: number | void, y: void, z: string | number | void) => void +>3 : 3 +>void 0 : undefined +>0 : 0 + +c(3); // ok +>c(3) : void +>c : (x: number | void, y: void, z: string | number | void) => void +>3 : 3 + +c(); // ok +>c() : void +>c : (x: number | void, y: void, z: string | number | void) => void + + +// Spread Parameters + +declare function call( +>call : (handler: (...args: TS) => void, ...args: TS) => void + + handler: (...args: TS) => void, +>handler : (...args: TS) => void +>args : TS + + ...args: TS): void; +>args : TS + +call((x: number, y: number) => x + y) // error +>call((x: number, y: number) => x + y) : any +>call : (handler: (...args: TS) => void, ...args: TS) => void +>(x: number, y: number) => x + y : (x: number, y: number) => number +>x : number +>y : number +>x + y : number +>x : number +>y : number + +call((x: number, y: number) => x + y, 4, 2) // ok +>call((x: number, y: number) => x + y, 4, 2) : void +>call : (handler: (...args: TS) => void, ...args: TS) => void +>(x: number, y: number) => x + y : (x: number, y: number) => number +>x : number +>y : number +>x + y : number +>x : number +>y : number +>4 : 4 +>2 : 2 + +call((x: number, y: void) => x, 4, void 0) // ok +>call((x: number, y: void) => x, 4, void 0) : void +>call : (handler: (...args: TS) => void, ...args: TS) => void +>(x: number, y: void) => x : (x: number, y: void) => number +>x : number +>y : void +>x : number +>4 : 4 +>void 0 : undefined +>0 : 0 + +call((x: number, y: void) => x, 4) // ok +>call((x: number, y: void) => x, 4) : any +>call : (handler: (...args: TS) => void, ...args: TS) => void +>(x: number, y: void) => x : (x: number, y: void) => number +>x : number +>y : void +>x : number +>4 : 4 + +call((x: void, y: void) => 42) // ok +>call((x: void, y: void) => 42) : any +>call : (handler: (...args: TS) => void, ...args: TS) => void +>(x: void, y: void) => 42 : (x: void, y: void) => number +>x : void +>y : void +>42 : 42 + +call((x: number | void, y: number | void) => 42) // ok +>call((x: number | void, y: number | void) => 42) : any +>call : (handler: (...args: TS) => void, ...args: TS) => void +>(x: number | void, y: number | void) => 42 : (x: number | void, y: number | void) => number +>x : number | void +>y : number | void +>42 : 42 + +call((x: number | void, y: number | void) => 42, 4) // ok +>call((x: number | void, y: number | void) => 42, 4) : any +>call : (handler: (...args: TS) => void, ...args: TS) => void +>(x: number | void, y: number | void) => 42 : (x: number | void, y: number | void) => number +>x : number | void +>y : number | void +>42 : 42 +>4 : 4 + +call((x: number | void, y: number | void) => 42, 4, 2) // ok +>call((x: number | void, y: number | void) => 42, 4, 2) : void +>call : (handler: (...args: TS) => void, ...args: TS) => void +>(x: number | void, y: number | void) => 42 : (x: number | void, y: number | void) => number +>x : number | void +>y : number | void +>42 : 42 +>4 : 4 +>2 : 2 + + diff --git a/tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts b/tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts new file mode 100644 index 0000000000000..f32ab02c9c36e --- /dev/null +++ b/tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts @@ -0,0 +1,82 @@ +// @strict: true + +// From #4260 +class X { + f(t: T) { + return { a: t }; + } +} + +declare const x: X; +x.f() // no error because f expects void + +declare const xUnion: X; +xUnion.f(42) // no error because f accepts number +xUnion.f() // no error because f accepts void + +declare const xAny: X; +xAny.f() // error, any still expects an argument + +declare const xUnknown: X; +xUnknown.f() // error, unknown still expects an argument + + +// Promise has previously been updated to work without arguments, but to show this fixes the issue too. + +class MyPromise { + constructor(executor: (resolve: (value: X) => void) => void) { + + } +} + +new MyPromise(resolve => resolve()); // no error +new MyPromise(resolve => resolve()); // no error +new MyPromise(resolve => resolve()); // error, `any` arguments cannot be omitted +new MyPromise(resolve => resolve()); // error, `unknown` arguments cannot be omitted + + +// Multiple parameters + +function a(x: number, y: string, z: void): void { + +} + +a(4, "hello"); // ok +a(4, "hello", void 0); // ok +a(4); // not ok + +function b(x: number, y: string, z: void, what: number): void { + +} + +b(4, "hello", void 0, 2); // ok +b(4, "hello"); // not ok +b(4, "hello", void 0); // not ok +b(4); // not ok + +function c(x: number | void, y: void, z: void | string | number): void { + +} + +c(3, void 0, void 0); // ok +c(3, void 0); // ok +c(3); // ok +c(); // ok + + +// Spread Parameters + +declare function call( + handler: (...args: TS) => void, + ...args: TS): void; + +call((x: number, y: number) => x + y) // error +call((x: number, y: number) => x + y, 4, 2) // ok + +call((x: number, y: void) => x, 4, void 0) // ok +call((x: number, y: void) => x, 4) // ok +call((x: void, y: void) => 42) // ok +call((x: number | void, y: number | void) => 42) // ok +call((x: number | void, y: number | void) => 42, 4) // ok +call((x: number | void, y: number | void) => 42, 4, 2) // ok + From f3b6eeab679991bb4193297e150ff91d84996b70 Mon Sep 17 00:00:00 2001 From: Jack Williams Date: Tue, 2 Oct 2018 22:08:42 +0100 Subject: [PATCH 2/3] Add never case --- .../reference/callWithMissingVoid.errors.txt | 43 +++-- .../reference/callWithMissingVoid.js | 4 + .../reference/callWithMissingVoid.symbols | 165 +++++++++--------- .../reference/callWithMissingVoid.types | 9 + .../functionCalls/callWithMissingVoid.ts | 3 + 5 files changed, 128 insertions(+), 96 deletions(-) diff --git a/tests/baselines/reference/callWithMissingVoid.errors.txt b/tests/baselines/reference/callWithMissingVoid.errors.txt index c37ea69b5e8cb..7a5958e5f27a5 100644 --- a/tests/baselines/reference/callWithMissingVoid.errors.txt +++ b/tests/baselines/reference/callWithMissingVoid.errors.txt @@ -1,19 +1,20 @@ tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(16,1): error TS2554: Expected 1 arguments, but got 0. tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(19,1): error TS2554: Expected 1 arguments, but got 0. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(32,31): error TS2554: Expected 1 arguments, but got 0. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(33,35): error TS2554: Expected 1 arguments, but got 0. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(44,1): error TS2554: Expected 3 arguments, but got 1. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(51,1): error TS2554: Expected 4 arguments, but got 2. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(52,1): error TS2554: Expected 4 arguments, but got 3. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(53,1): error TS2554: Expected 4 arguments, but got 1. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(71,6): error TS2345: Argument of type '(x: number, y: number) => number' is not assignable to parameter of type '() => void'. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(75,6): error TS2345: Argument of type '(x: number, y: void) => number' is not assignable to parameter of type '(args_0: number) => void'. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(76,6): error TS2345: Argument of type '(x: void, y: void) => number' is not assignable to parameter of type '() => void'. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(77,6): error TS2345: Argument of type '(x: number | void, y: number | void) => number' is not assignable to parameter of type '() => void'. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(78,6): error TS2345: Argument of type '(x: number | void, y: number | void) => number' is not assignable to parameter of type '(args_0: number) => void'. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(22,1): error TS2554: Expected 1 arguments, but got 0. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(35,31): error TS2554: Expected 1 arguments, but got 0. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(36,35): error TS2554: Expected 1 arguments, but got 0. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(47,1): error TS2554: Expected 3 arguments, but got 1. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(54,1): error TS2554: Expected 4 arguments, but got 2. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(55,1): error TS2554: Expected 4 arguments, but got 3. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(56,1): error TS2554: Expected 4 arguments, but got 1. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(74,6): error TS2345: Argument of type '(x: number, y: number) => number' is not assignable to parameter of type '() => void'. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(78,6): error TS2345: Argument of type '(x: number, y: void) => number' is not assignable to parameter of type '(args_0: number) => void'. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(79,6): error TS2345: Argument of type '(x: void, y: void) => number' is not assignable to parameter of type '() => void'. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(80,6): error TS2345: Argument of type '(x: number | void, y: number | void) => number' is not assignable to parameter of type '() => void'. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(81,6): error TS2345: Argument of type '(x: number | void, y: number | void) => number' is not assignable to parameter of type '(args_0: number) => void'. -==== tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts (13 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts (14 errors) ==== // From #4260 class X { f(t: T) { @@ -40,6 +41,12 @@ tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(78,6): !!! error TS2554: Expected 1 arguments, but got 0. !!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:3:7: An argument for 't' was not provided. + declare const xNever: X; + xNever.f() // error, never still expects an argument + ~~~~~~~~~~ +!!! error TS2554: Expected 1 arguments, but got 0. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:3:7: An argument for 't' was not provided. + // Promise has previously been updated to work without arguments, but to show this fixes the issue too. @@ -54,11 +61,11 @@ tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(78,6): new MyPromise(resolve => resolve()); // error, `any` arguments cannot be omitted ~~~~~~~~~ !!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:25:38: An argument for 'value' was not provided. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:28:38: An argument for 'value' was not provided. new MyPromise(resolve => resolve()); // error, `unknown` arguments cannot be omitted ~~~~~~~~~ !!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:25:38: An argument for 'value' was not provided. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:28:38: An argument for 'value' was not provided. // Multiple parameters @@ -72,7 +79,7 @@ tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(78,6): a(4); // not ok ~~~~ !!! error TS2554: Expected 3 arguments, but got 1. -!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:38:23: An argument for 'y' was not provided. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:41:23: An argument for 'y' was not provided. function b(x: number, y: string, z: void, what: number): void { @@ -82,15 +89,15 @@ tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(78,6): b(4, "hello"); // not ok ~~~~~~~~~~~~~ !!! error TS2554: Expected 4 arguments, but got 2. -!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:46:34: An argument for 'z' was not provided. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:49:34: An argument for 'z' was not provided. b(4, "hello", void 0); // not ok ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2554: Expected 4 arguments, but got 3. -!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:46:43: An argument for 'what' was not provided. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:49:43: An argument for 'what' was not provided. b(4); // not ok ~~~~ !!! error TS2554: Expected 4 arguments, but got 1. -!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:46:23: An argument for 'y' was not provided. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:49:23: An argument for 'y' was not provided. function c(x: number | void, y: void, z: void | string | number): void { diff --git a/tests/baselines/reference/callWithMissingVoid.js b/tests/baselines/reference/callWithMissingVoid.js index 4437053298706..8b11e2b429cc3 100644 --- a/tests/baselines/reference/callWithMissingVoid.js +++ b/tests/baselines/reference/callWithMissingVoid.js @@ -19,6 +19,9 @@ xAny.f() // error, any still expects an argument declare const xUnknown: X; xUnknown.f() // error, unknown still expects an argument +declare const xNever: X; +xNever.f() // error, never still expects an argument + // Promise has previously been updated to work without arguments, but to show this fixes the issue too. @@ -97,6 +100,7 @@ xUnion.f(42); // no error because f accepts number xUnion.f(); // no error because f accepts void xAny.f(); // error, any still expects an argument xUnknown.f(); // error, unknown still expects an argument +xNever.f(); // error, never still expects an argument // Promise has previously been updated to work without arguments, but to show this fixes the issue too. var MyPromise = /** @class */ (function () { function MyPromise(executor) { diff --git a/tests/baselines/reference/callWithMissingVoid.symbols b/tests/baselines/reference/callWithMissingVoid.symbols index f5c7b741023ae..16483e524248b 100644 --- a/tests/baselines/reference/callWithMissingVoid.symbols +++ b/tests/baselines/reference/callWithMissingVoid.symbols @@ -56,163 +56,172 @@ xUnknown.f() // error, unknown still expects an argument >xUnknown : Symbol(xUnknown, Decl(callWithMissingVoid.ts, 17, 13)) >f : Symbol(X.f, Decl(callWithMissingVoid.ts, 1, 12)) +declare const xNever: X; +>xNever : Symbol(xNever, Decl(callWithMissingVoid.ts, 20, 13)) +>X : Symbol(X, Decl(callWithMissingVoid.ts, 0, 0)) + +xNever.f() // error, never still expects an argument +>xNever.f : Symbol(X.f, Decl(callWithMissingVoid.ts, 1, 12)) +>xNever : Symbol(xNever, Decl(callWithMissingVoid.ts, 20, 13)) +>f : Symbol(X.f, Decl(callWithMissingVoid.ts, 1, 12)) + // Promise has previously been updated to work without arguments, but to show this fixes the issue too. class MyPromise { ->MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 18, 12)) ->X : Symbol(X, Decl(callWithMissingVoid.ts, 23, 16)) +>MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 21, 10)) +>X : Symbol(X, Decl(callWithMissingVoid.ts, 26, 16)) constructor(executor: (resolve: (value: X) => void) => void) { ->executor : Symbol(executor, Decl(callWithMissingVoid.ts, 24, 16)) ->resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 24, 27)) ->value : Symbol(value, Decl(callWithMissingVoid.ts, 24, 37)) ->X : Symbol(X, Decl(callWithMissingVoid.ts, 23, 16)) +>executor : Symbol(executor, Decl(callWithMissingVoid.ts, 27, 16)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 27, 27)) +>value : Symbol(value, Decl(callWithMissingVoid.ts, 27, 37)) +>X : Symbol(X, Decl(callWithMissingVoid.ts, 26, 16)) } } new MyPromise(resolve => resolve()); // no error ->MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 18, 12)) ->resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 29, 20)) ->resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 29, 20)) +>MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 21, 10)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 32, 20)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 32, 20)) new MyPromise(resolve => resolve()); // no error ->MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 18, 12)) ->resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 30, 29)) ->resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 30, 29)) +>MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 21, 10)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 33, 29)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 33, 29)) new MyPromise(resolve => resolve()); // error, `any` arguments cannot be omitted ->MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 18, 12)) ->resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 31, 19)) ->resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 31, 19)) +>MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 21, 10)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 34, 19)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 34, 19)) new MyPromise(resolve => resolve()); // error, `unknown` arguments cannot be omitted ->MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 18, 12)) ->resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 32, 23)) ->resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 32, 23)) +>MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 21, 10)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 35, 23)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 35, 23)) // Multiple parameters function a(x: number, y: string, z: void): void { ->a : Symbol(a, Decl(callWithMissingVoid.ts, 32, 45)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 37, 11)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 37, 21)) ->z : Symbol(z, Decl(callWithMissingVoid.ts, 37, 32)) +>a : Symbol(a, Decl(callWithMissingVoid.ts, 35, 45)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 40, 11)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 40, 21)) +>z : Symbol(z, Decl(callWithMissingVoid.ts, 40, 32)) } a(4, "hello"); // ok ->a : Symbol(a, Decl(callWithMissingVoid.ts, 32, 45)) +>a : Symbol(a, Decl(callWithMissingVoid.ts, 35, 45)) a(4, "hello", void 0); // ok ->a : Symbol(a, Decl(callWithMissingVoid.ts, 32, 45)) +>a : Symbol(a, Decl(callWithMissingVoid.ts, 35, 45)) a(4); // not ok ->a : Symbol(a, Decl(callWithMissingVoid.ts, 32, 45)) +>a : Symbol(a, Decl(callWithMissingVoid.ts, 35, 45)) function b(x: number, y: string, z: void, what: number): void { ->b : Symbol(b, Decl(callWithMissingVoid.ts, 43, 5)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 45, 11)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 45, 21)) ->z : Symbol(z, Decl(callWithMissingVoid.ts, 45, 32)) ->what : Symbol(what, Decl(callWithMissingVoid.ts, 45, 41)) +>b : Symbol(b, Decl(callWithMissingVoid.ts, 46, 5)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 48, 11)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 48, 21)) +>z : Symbol(z, Decl(callWithMissingVoid.ts, 48, 32)) +>what : Symbol(what, Decl(callWithMissingVoid.ts, 48, 41)) } b(4, "hello", void 0, 2); // ok ->b : Symbol(b, Decl(callWithMissingVoid.ts, 43, 5)) +>b : Symbol(b, Decl(callWithMissingVoid.ts, 46, 5)) b(4, "hello"); // not ok ->b : Symbol(b, Decl(callWithMissingVoid.ts, 43, 5)) +>b : Symbol(b, Decl(callWithMissingVoid.ts, 46, 5)) b(4, "hello", void 0); // not ok ->b : Symbol(b, Decl(callWithMissingVoid.ts, 43, 5)) +>b : Symbol(b, Decl(callWithMissingVoid.ts, 46, 5)) b(4); // not ok ->b : Symbol(b, Decl(callWithMissingVoid.ts, 43, 5)) +>b : Symbol(b, Decl(callWithMissingVoid.ts, 46, 5)) function c(x: number | void, y: void, z: void | string | number): void { ->c : Symbol(c, Decl(callWithMissingVoid.ts, 52, 5)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 54, 11)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 54, 28)) ->z : Symbol(z, Decl(callWithMissingVoid.ts, 54, 37)) +>c : Symbol(c, Decl(callWithMissingVoid.ts, 55, 5)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 57, 11)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 57, 28)) +>z : Symbol(z, Decl(callWithMissingVoid.ts, 57, 37)) } c(3, void 0, void 0); // ok ->c : Symbol(c, Decl(callWithMissingVoid.ts, 52, 5)) +>c : Symbol(c, Decl(callWithMissingVoid.ts, 55, 5)) c(3, void 0); // ok ->c : Symbol(c, Decl(callWithMissingVoid.ts, 52, 5)) +>c : Symbol(c, Decl(callWithMissingVoid.ts, 55, 5)) c(3); // ok ->c : Symbol(c, Decl(callWithMissingVoid.ts, 52, 5)) +>c : Symbol(c, Decl(callWithMissingVoid.ts, 55, 5)) c(); // ok ->c : Symbol(c, Decl(callWithMissingVoid.ts, 52, 5)) +>c : Symbol(c, Decl(callWithMissingVoid.ts, 55, 5)) // Spread Parameters declare function call( ->call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) ->TS : Symbol(TS, Decl(callWithMissingVoid.ts, 66, 22)) +>call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) +>TS : Symbol(TS, Decl(callWithMissingVoid.ts, 69, 22)) handler: (...args: TS) => void, ->handler : Symbol(handler, Decl(callWithMissingVoid.ts, 66, 44)) ->args : Symbol(args, Decl(callWithMissingVoid.ts, 67, 14)) ->TS : Symbol(TS, Decl(callWithMissingVoid.ts, 66, 22)) +>handler : Symbol(handler, Decl(callWithMissingVoid.ts, 69, 44)) +>args : Symbol(args, Decl(callWithMissingVoid.ts, 70, 14)) +>TS : Symbol(TS, Decl(callWithMissingVoid.ts, 69, 22)) ...args: TS): void; ->args : Symbol(args, Decl(callWithMissingVoid.ts, 67, 35)) ->TS : Symbol(TS, Decl(callWithMissingVoid.ts, 66, 22)) +>args : Symbol(args, Decl(callWithMissingVoid.ts, 70, 35)) +>TS : Symbol(TS, Decl(callWithMissingVoid.ts, 69, 22)) call((x: number, y: number) => x + y) // error ->call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 70, 6)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 70, 16)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 70, 6)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 70, 16)) - -call((x: number, y: number) => x + y, 4, 2) // ok ->call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 71, 6)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 71, 16)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 71, 6)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 71, 16)) - -call((x: number, y: void) => x, 4, void 0) // ok ->call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) +>call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) >x : Symbol(x, Decl(callWithMissingVoid.ts, 73, 6)) >y : Symbol(y, Decl(callWithMissingVoid.ts, 73, 16)) >x : Symbol(x, Decl(callWithMissingVoid.ts, 73, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 73, 16)) -call((x: number, y: void) => x, 4) // ok ->call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) +call((x: number, y: number) => x + y, 4, 2) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) >x : Symbol(x, Decl(callWithMissingVoid.ts, 74, 6)) >y : Symbol(y, Decl(callWithMissingVoid.ts, 74, 16)) >x : Symbol(x, Decl(callWithMissingVoid.ts, 74, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 74, 16)) + +call((x: number, y: void) => x, 4, void 0) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 76, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 76, 16)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 76, 6)) + +call((x: number, y: void) => x, 4) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 77, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 77, 16)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 77, 6)) call((x: void, y: void) => 42) // ok ->call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 75, 6)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 75, 14)) +>call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 78, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 78, 14)) call((x: number | void, y: number | void) => 42) // ok ->call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 76, 6)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 76, 23)) +>call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 79, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 79, 23)) call((x: number | void, y: number | void) => 42, 4) // ok ->call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 77, 6)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 77, 23)) +>call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 80, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 80, 23)) call((x: number | void, y: number | void) => 42, 4, 2) // ok ->call : Symbol(call, Decl(callWithMissingVoid.ts, 61, 4)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 78, 6)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 78, 23)) +>call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 81, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 81, 23)) diff --git a/tests/baselines/reference/callWithMissingVoid.types b/tests/baselines/reference/callWithMissingVoid.types index 6a2b74c379455..1bdcb2f19544b 100644 --- a/tests/baselines/reference/callWithMissingVoid.types +++ b/tests/baselines/reference/callWithMissingVoid.types @@ -57,6 +57,15 @@ xUnknown.f() // error, unknown still expects an argument >xUnknown : X >f : (t: unknown) => { a: unknown; } +declare const xNever: X; +>xNever : X + +xNever.f() // error, never still expects an argument +>xNever.f() : { a: never; } +>xNever.f : (t: never) => { a: never; } +>xNever : X +>f : (t: never) => { a: never; } + // Promise has previously been updated to work without arguments, but to show this fixes the issue too. diff --git a/tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts b/tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts index f32ab02c9c36e..34281cb86c234 100644 --- a/tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts +++ b/tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts @@ -20,6 +20,9 @@ xAny.f() // error, any still expects an argument declare const xUnknown: X; xUnknown.f() // error, unknown still expects an argument +declare const xNever: X; +xNever.f() // error, never still expects an argument + // Promise has previously been updated to work without arguments, but to show this fixes the issue too. From f9afb15ce8c5ad979a0fa357a138f08cc4bd7b2a Mon Sep 17 00:00:00 2001 From: Jack Williams Date: Tue, 2 Oct 2018 22:55:15 +0100 Subject: [PATCH 3/3] Fix baselines --- .../reference/callWithMissingVoid.errors.txt | 44 +++---- .../reference/callWithMissingVoid.js | 4 +- .../reference/callWithMissingVoid.symbols | 119 +++++++++--------- .../reference/callWithMissingVoid.types | 38 +++--- .../functionCalls/callWithMissingVoid.ts | 3 +- 5 files changed, 109 insertions(+), 99 deletions(-) diff --git a/tests/baselines/reference/callWithMissingVoid.errors.txt b/tests/baselines/reference/callWithMissingVoid.errors.txt index 7a5958e5f27a5..222b9aa008de6 100644 --- a/tests/baselines/reference/callWithMissingVoid.errors.txt +++ b/tests/baselines/reference/callWithMissingVoid.errors.txt @@ -3,18 +3,15 @@ tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(19,1): tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(22,1): error TS2554: Expected 1 arguments, but got 0. tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(35,31): error TS2554: Expected 1 arguments, but got 0. tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(36,35): error TS2554: Expected 1 arguments, but got 0. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(47,1): error TS2554: Expected 3 arguments, but got 1. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(54,1): error TS2554: Expected 4 arguments, but got 2. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(55,1): error TS2554: Expected 4 arguments, but got 3. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(56,1): error TS2554: Expected 4 arguments, but got 1. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(74,6): error TS2345: Argument of type '(x: number, y: number) => number' is not assignable to parameter of type '() => void'. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(78,6): error TS2345: Argument of type '(x: number, y: void) => number' is not assignable to parameter of type '(args_0: number) => void'. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(79,6): error TS2345: Argument of type '(x: void, y: void) => number' is not assignable to parameter of type '() => void'. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(80,6): error TS2345: Argument of type '(x: number | void, y: number | void) => number' is not assignable to parameter of type '() => void'. -tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(81,6): error TS2345: Argument of type '(x: number | void, y: number | void) => number' is not assignable to parameter of type '(args_0: number) => void'. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(37,33): error TS2554: Expected 1 arguments, but got 0. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(48,1): error TS2554: Expected 3 arguments, but got 1. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(55,1): error TS2554: Expected 4 arguments, but got 2. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(56,1): error TS2554: Expected 4 arguments, but got 3. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(57,1): error TS2554: Expected 4 arguments, but got 1. +tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(75,1): error TS2554: Expected 3 arguments, but got 1. -==== tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts (14 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts (11 errors) ==== // From #4260 class X { f(t: T) { @@ -65,6 +62,10 @@ tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(81,6): new MyPromise(resolve => resolve()); // error, `unknown` arguments cannot be omitted ~~~~~~~~~ !!! error TS2554: Expected 1 arguments, but got 0. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:28:38: An argument for 'value' was not provided. + new MyPromise(resolve => resolve()); // error, `never` arguments cannot be omitted + ~~~~~~~~~ +!!! error TS2554: Expected 1 arguments, but got 0. !!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:28:38: An argument for 'value' was not provided. @@ -79,7 +80,7 @@ tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(81,6): a(4); // not ok ~~~~ !!! error TS2554: Expected 3 arguments, but got 1. -!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:41:23: An argument for 'y' was not provided. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:42:23: An argument for 'y' was not provided. function b(x: number, y: string, z: void, what: number): void { @@ -89,15 +90,15 @@ tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(81,6): b(4, "hello"); // not ok ~~~~~~~~~~~~~ !!! error TS2554: Expected 4 arguments, but got 2. -!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:49:34: An argument for 'z' was not provided. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:50:34: An argument for 'z' was not provided. b(4, "hello", void 0); // not ok ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2554: Expected 4 arguments, but got 3. -!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:49:43: An argument for 'what' was not provided. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:50:43: An argument for 'what' was not provided. b(4); // not ok ~~~~ !!! error TS2554: Expected 4 arguments, but got 1. -!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:49:23: An argument for 'y' was not provided. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:50:23: An argument for 'y' was not provided. function c(x: number | void, y: void, z: void | string | number): void { @@ -112,27 +113,20 @@ tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(81,6): // Spread Parameters declare function call( - handler: (...args: TS) => void, + handler: (...args: TS) => unknown, ...args: TS): void; call((x: number, y: number) => x + y) // error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: number, y: number) => number' is not assignable to parameter of type '() => void'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2554: Expected 3 arguments, but got 1. +!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:73:5: An argument for 'args' was not provided. call((x: number, y: number) => x + y, 4, 2) // ok call((x: number, y: void) => x, 4, void 0) // ok call((x: number, y: void) => x, 4) // ok - ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: number, y: void) => number' is not assignable to parameter of type '(args_0: number) => void'. call((x: void, y: void) => 42) // ok - ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: void, y: void) => number' is not assignable to parameter of type '() => void'. call((x: number | void, y: number | void) => 42) // ok - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: number | void, y: number | void) => number' is not assignable to parameter of type '() => void'. call((x: number | void, y: number | void) => 42, 4) // ok - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: number | void, y: number | void) => number' is not assignable to parameter of type '(args_0: number) => void'. call((x: number | void, y: number | void) => 42, 4, 2) // ok \ No newline at end of file diff --git a/tests/baselines/reference/callWithMissingVoid.js b/tests/baselines/reference/callWithMissingVoid.js index 8b11e2b429cc3..5c18fa79d8700 100644 --- a/tests/baselines/reference/callWithMissingVoid.js +++ b/tests/baselines/reference/callWithMissingVoid.js @@ -35,6 +35,7 @@ new MyPromise(resolve => resolve()); // no error new MyPromise(resolve => resolve()); // no error new MyPromise(resolve => resolve()); // error, `any` arguments cannot be omitted new MyPromise(resolve => resolve()); // error, `unknown` arguments cannot be omitted +new MyPromise(resolve => resolve()); // error, `never` arguments cannot be omitted // Multiple parameters @@ -69,7 +70,7 @@ c(); // ok // Spread Parameters declare function call( - handler: (...args: TS) => void, + handler: (...args: TS) => unknown, ...args: TS): void; call((x: number, y: number) => x + y) // error @@ -111,6 +112,7 @@ new MyPromise(function (resolve) { return resolve(); }); // no error new MyPromise(function (resolve) { return resolve(); }); // no error new MyPromise(function (resolve) { return resolve(); }); // error, `any` arguments cannot be omitted new MyPromise(function (resolve) { return resolve(); }); // error, `unknown` arguments cannot be omitted +new MyPromise(function (resolve) { return resolve(); }); // error, `never` arguments cannot be omitted // Multiple parameters function a(x, y, z) { } diff --git a/tests/baselines/reference/callWithMissingVoid.symbols b/tests/baselines/reference/callWithMissingVoid.symbols index 16483e524248b..d1a3ecdc0f3d9 100644 --- a/tests/baselines/reference/callWithMissingVoid.symbols +++ b/tests/baselines/reference/callWithMissingVoid.symbols @@ -101,127 +101,132 @@ new MyPromise(resolve => resolve()); // error, `unknown` arguments cann >resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 35, 23)) >resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 35, 23)) +new MyPromise(resolve => resolve()); // error, `never` arguments cannot be omitted +>MyPromise : Symbol(MyPromise, Decl(callWithMissingVoid.ts, 21, 10)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 36, 21)) +>resolve : Symbol(resolve, Decl(callWithMissingVoid.ts, 36, 21)) + // Multiple parameters function a(x: number, y: string, z: void): void { ->a : Symbol(a, Decl(callWithMissingVoid.ts, 35, 45)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 40, 11)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 40, 21)) ->z : Symbol(z, Decl(callWithMissingVoid.ts, 40, 32)) +>a : Symbol(a, Decl(callWithMissingVoid.ts, 36, 43)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 41, 11)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 41, 21)) +>z : Symbol(z, Decl(callWithMissingVoid.ts, 41, 32)) } a(4, "hello"); // ok ->a : Symbol(a, Decl(callWithMissingVoid.ts, 35, 45)) +>a : Symbol(a, Decl(callWithMissingVoid.ts, 36, 43)) a(4, "hello", void 0); // ok ->a : Symbol(a, Decl(callWithMissingVoid.ts, 35, 45)) +>a : Symbol(a, Decl(callWithMissingVoid.ts, 36, 43)) a(4); // not ok ->a : Symbol(a, Decl(callWithMissingVoid.ts, 35, 45)) +>a : Symbol(a, Decl(callWithMissingVoid.ts, 36, 43)) function b(x: number, y: string, z: void, what: number): void { ->b : Symbol(b, Decl(callWithMissingVoid.ts, 46, 5)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 48, 11)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 48, 21)) ->z : Symbol(z, Decl(callWithMissingVoid.ts, 48, 32)) ->what : Symbol(what, Decl(callWithMissingVoid.ts, 48, 41)) +>b : Symbol(b, Decl(callWithMissingVoid.ts, 47, 5)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 49, 11)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 49, 21)) +>z : Symbol(z, Decl(callWithMissingVoid.ts, 49, 32)) +>what : Symbol(what, Decl(callWithMissingVoid.ts, 49, 41)) } b(4, "hello", void 0, 2); // ok ->b : Symbol(b, Decl(callWithMissingVoid.ts, 46, 5)) +>b : Symbol(b, Decl(callWithMissingVoid.ts, 47, 5)) b(4, "hello"); // not ok ->b : Symbol(b, Decl(callWithMissingVoid.ts, 46, 5)) +>b : Symbol(b, Decl(callWithMissingVoid.ts, 47, 5)) b(4, "hello", void 0); // not ok ->b : Symbol(b, Decl(callWithMissingVoid.ts, 46, 5)) +>b : Symbol(b, Decl(callWithMissingVoid.ts, 47, 5)) b(4); // not ok ->b : Symbol(b, Decl(callWithMissingVoid.ts, 46, 5)) +>b : Symbol(b, Decl(callWithMissingVoid.ts, 47, 5)) function c(x: number | void, y: void, z: void | string | number): void { ->c : Symbol(c, Decl(callWithMissingVoid.ts, 55, 5)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 57, 11)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 57, 28)) ->z : Symbol(z, Decl(callWithMissingVoid.ts, 57, 37)) +>c : Symbol(c, Decl(callWithMissingVoid.ts, 56, 5)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 58, 11)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 58, 28)) +>z : Symbol(z, Decl(callWithMissingVoid.ts, 58, 37)) } c(3, void 0, void 0); // ok ->c : Symbol(c, Decl(callWithMissingVoid.ts, 55, 5)) +>c : Symbol(c, Decl(callWithMissingVoid.ts, 56, 5)) c(3, void 0); // ok ->c : Symbol(c, Decl(callWithMissingVoid.ts, 55, 5)) +>c : Symbol(c, Decl(callWithMissingVoid.ts, 56, 5)) c(3); // ok ->c : Symbol(c, Decl(callWithMissingVoid.ts, 55, 5)) +>c : Symbol(c, Decl(callWithMissingVoid.ts, 56, 5)) c(); // ok ->c : Symbol(c, Decl(callWithMissingVoid.ts, 55, 5)) +>c : Symbol(c, Decl(callWithMissingVoid.ts, 56, 5)) // Spread Parameters declare function call( ->call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) ->TS : Symbol(TS, Decl(callWithMissingVoid.ts, 69, 22)) +>call : Symbol(call, Decl(callWithMissingVoid.ts, 65, 4)) +>TS : Symbol(TS, Decl(callWithMissingVoid.ts, 70, 22)) - handler: (...args: TS) => void, ->handler : Symbol(handler, Decl(callWithMissingVoid.ts, 69, 44)) ->args : Symbol(args, Decl(callWithMissingVoid.ts, 70, 14)) ->TS : Symbol(TS, Decl(callWithMissingVoid.ts, 69, 22)) + handler: (...args: TS) => unknown, +>handler : Symbol(handler, Decl(callWithMissingVoid.ts, 70, 44)) +>args : Symbol(args, Decl(callWithMissingVoid.ts, 71, 14)) +>TS : Symbol(TS, Decl(callWithMissingVoid.ts, 70, 22)) ...args: TS): void; ->args : Symbol(args, Decl(callWithMissingVoid.ts, 70, 35)) ->TS : Symbol(TS, Decl(callWithMissingVoid.ts, 69, 22)) +>args : Symbol(args, Decl(callWithMissingVoid.ts, 71, 38)) +>TS : Symbol(TS, Decl(callWithMissingVoid.ts, 70, 22)) call((x: number, y: number) => x + y) // error ->call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 73, 6)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 73, 16)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 73, 6)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 73, 16)) - -call((x: number, y: number) => x + y, 4, 2) // ok ->call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) +>call : Symbol(call, Decl(callWithMissingVoid.ts, 65, 4)) >x : Symbol(x, Decl(callWithMissingVoid.ts, 74, 6)) >y : Symbol(y, Decl(callWithMissingVoid.ts, 74, 16)) >x : Symbol(x, Decl(callWithMissingVoid.ts, 74, 6)) >y : Symbol(y, Decl(callWithMissingVoid.ts, 74, 16)) -call((x: number, y: void) => x, 4, void 0) // ok ->call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 76, 6)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 76, 16)) ->x : Symbol(x, Decl(callWithMissingVoid.ts, 76, 6)) +call((x: number, y: number) => x + y, 4, 2) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 65, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 75, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 75, 16)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 75, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 75, 16)) -call((x: number, y: void) => x, 4) // ok ->call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) +call((x: number, y: void) => x, 4, void 0) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 65, 4)) >x : Symbol(x, Decl(callWithMissingVoid.ts, 77, 6)) >y : Symbol(y, Decl(callWithMissingVoid.ts, 77, 16)) >x : Symbol(x, Decl(callWithMissingVoid.ts, 77, 6)) -call((x: void, y: void) => 42) // ok ->call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) +call((x: number, y: void) => x, 4) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 65, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 78, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 78, 16)) >x : Symbol(x, Decl(callWithMissingVoid.ts, 78, 6)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 78, 14)) -call((x: number | void, y: number | void) => 42) // ok ->call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) +call((x: void, y: void) => 42) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 65, 4)) >x : Symbol(x, Decl(callWithMissingVoid.ts, 79, 6)) ->y : Symbol(y, Decl(callWithMissingVoid.ts, 79, 23)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 79, 14)) -call((x: number | void, y: number | void) => 42, 4) // ok ->call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) +call((x: number | void, y: number | void) => 42) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 65, 4)) >x : Symbol(x, Decl(callWithMissingVoid.ts, 80, 6)) >y : Symbol(y, Decl(callWithMissingVoid.ts, 80, 23)) -call((x: number | void, y: number | void) => 42, 4, 2) // ok ->call : Symbol(call, Decl(callWithMissingVoid.ts, 64, 4)) +call((x: number | void, y: number | void) => 42, 4) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 65, 4)) >x : Symbol(x, Decl(callWithMissingVoid.ts, 81, 6)) >y : Symbol(y, Decl(callWithMissingVoid.ts, 81, 23)) +call((x: number | void, y: number | void) => 42, 4, 2) // ok +>call : Symbol(call, Decl(callWithMissingVoid.ts, 65, 4)) +>x : Symbol(x, Decl(callWithMissingVoid.ts, 82, 6)) +>y : Symbol(y, Decl(callWithMissingVoid.ts, 82, 23)) + diff --git a/tests/baselines/reference/callWithMissingVoid.types b/tests/baselines/reference/callWithMissingVoid.types index 1bdcb2f19544b..199ea228d899d 100644 --- a/tests/baselines/reference/callWithMissingVoid.types +++ b/tests/baselines/reference/callWithMissingVoid.types @@ -112,6 +112,14 @@ new MyPromise(resolve => resolve()); // error, `unknown` arguments cann >resolve() : void >resolve : (value: unknown) => void +new MyPromise(resolve => resolve()); // error, `never` arguments cannot be omitted +>new MyPromise(resolve => resolve()) : MyPromise +>MyPromise : typeof MyPromise +>resolve => resolve() : (resolve: (value: never) => void) => any +>resolve : (value: never) => void +>resolve() : void +>resolve : (value: never) => void + // Multiple parameters @@ -216,10 +224,10 @@ c(); // ok // Spread Parameters declare function call( ->call : (handler: (...args: TS) => void, ...args: TS) => void +>call : (handler: (...args: TS) => unknown, ...args: TS) => void - handler: (...args: TS) => void, ->handler : (...args: TS) => void + handler: (...args: TS) => unknown, +>handler : (...args: TS) => unknown >args : TS ...args: TS): void; @@ -227,7 +235,7 @@ declare function call( call((x: number, y: number) => x + y) // error >call((x: number, y: number) => x + y) : any ->call : (handler: (...args: TS) => void, ...args: TS) => void +>call : (handler: (...args: TS) => unknown, ...args: TS) => void >(x: number, y: number) => x + y : (x: number, y: number) => number >x : number >y : number @@ -237,7 +245,7 @@ call((x: number, y: number) => x + y) // error call((x: number, y: number) => x + y, 4, 2) // ok >call((x: number, y: number) => x + y, 4, 2) : void ->call : (handler: (...args: TS) => void, ...args: TS) => void +>call : (handler: (...args: TS) => unknown, ...args: TS) => void >(x: number, y: number) => x + y : (x: number, y: number) => number >x : number >y : number @@ -249,7 +257,7 @@ call((x: number, y: number) => x + y, 4, 2) // ok call((x: number, y: void) => x, 4, void 0) // ok >call((x: number, y: void) => x, 4, void 0) : void ->call : (handler: (...args: TS) => void, ...args: TS) => void +>call : (handler: (...args: TS) => unknown, ...args: TS) => void >(x: number, y: void) => x : (x: number, y: void) => number >x : number >y : void @@ -259,8 +267,8 @@ call((x: number, y: void) => x, 4, void 0) // ok >0 : 0 call((x: number, y: void) => x, 4) // ok ->call((x: number, y: void) => x, 4) : any ->call : (handler: (...args: TS) => void, ...args: TS) => void +>call((x: number, y: void) => x, 4) : void +>call : (handler: (...args: TS) => unknown, ...args: TS) => void >(x: number, y: void) => x : (x: number, y: void) => number >x : number >y : void @@ -268,24 +276,24 @@ call((x: number, y: void) => x, 4) // ok >4 : 4 call((x: void, y: void) => 42) // ok ->call((x: void, y: void) => 42) : any ->call : (handler: (...args: TS) => void, ...args: TS) => void +>call((x: void, y: void) => 42) : void +>call : (handler: (...args: TS) => unknown, ...args: TS) => void >(x: void, y: void) => 42 : (x: void, y: void) => number >x : void >y : void >42 : 42 call((x: number | void, y: number | void) => 42) // ok ->call((x: number | void, y: number | void) => 42) : any ->call : (handler: (...args: TS) => void, ...args: TS) => void +>call((x: number | void, y: number | void) => 42) : void +>call : (handler: (...args: TS) => unknown, ...args: TS) => void >(x: number | void, y: number | void) => 42 : (x: number | void, y: number | void) => number >x : number | void >y : number | void >42 : 42 call((x: number | void, y: number | void) => 42, 4) // ok ->call((x: number | void, y: number | void) => 42, 4) : any ->call : (handler: (...args: TS) => void, ...args: TS) => void +>call((x: number | void, y: number | void) => 42, 4) : void +>call : (handler: (...args: TS) => unknown, ...args: TS) => void >(x: number | void, y: number | void) => 42 : (x: number | void, y: number | void) => number >x : number | void >y : number | void @@ -294,7 +302,7 @@ call((x: number | void, y: number | void) => 42, 4) // ok call((x: number | void, y: number | void) => 42, 4, 2) // ok >call((x: number | void, y: number | void) => 42, 4, 2) : void ->call : (handler: (...args: TS) => void, ...args: TS) => void +>call : (handler: (...args: TS) => unknown, ...args: TS) => void >(x: number | void, y: number | void) => 42 : (x: number | void, y: number | void) => number >x : number | void >y : number | void diff --git a/tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts b/tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts index 34281cb86c234..d9b005614fa02 100644 --- a/tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts +++ b/tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts @@ -36,6 +36,7 @@ new MyPromise(resolve => resolve()); // no error new MyPromise(resolve => resolve()); // no error new MyPromise(resolve => resolve()); // error, `any` arguments cannot be omitted new MyPromise(resolve => resolve()); // error, `unknown` arguments cannot be omitted +new MyPromise(resolve => resolve()); // error, `never` arguments cannot be omitted // Multiple parameters @@ -70,7 +71,7 @@ c(); // ok // Spread Parameters declare function call( - handler: (...args: TS) => void, + handler: (...args: TS) => unknown, ...args: TS): void; call((x: number, y: number) => x + y) // error