1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
//// [callWithMissingVoid.ts]
// From #4260
class X<T> {
f(t: T) {
return { a: t };
}
}
declare const x: X<void>;
x.f() // no error because f expects void
declare const xUnion: X<void | number>;
xUnion.f(42) // no error because f accepts number
xUnion.f() // no error because f accepts void
declare const xAny: X<any>;
xAny.f() // error, any still expects an argument
declare const xUnknown: X<unknown>;
xUnknown.f() // error, unknown still expects an argument
declare const xNever: X<never>;
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.
class MyPromise<X> {
constructor(executor: (resolve: (value: X) => void) => void) {
}
}
new MyPromise<void>(resolve => resolve()); // no error
new MyPromise<void | number>(resolve => resolve()); // no error
new MyPromise<any>(resolve => resolve()); // error, `any` arguments cannot be omitted
new MyPromise<unknown>(resolve => resolve()); // error, `unknown` arguments cannot be omitted
new MyPromise<never>(resolve => resolve()); // error, `never` 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<TS extends unknown[]>(
handler: (...args: TS) => unknown,
...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
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) {
}
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
new MyPromise(function (resolve) { return resolve(); }); // error, `never` 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
|