2016-12-23 22:31:38 +03:00
|
|
|
exports[`test issue-518.js 1`] = `
|
|
|
|
"function doSomethingAsync(): Promise<void> {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
resolve(); // OK to leave out arg, same as resolve(undefined)
|
|
|
|
|
|
|
|
var anotherVoidPromise: Promise<void> = Promise.resolve();
|
|
|
|
resolve(anotherVoidPromise);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// simpler repro to show that too few args are fine when expecting void
|
|
|
|
function foo(x: void) { }
|
|
|
|
foo();
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2016-12-27 21:29:31 +03:00
|
|
|
function doSomethingAsync(): Promise<void> {
|
2017-01-04 23:24:10 +03:00
|
|
|
return new Promise((resolve, reject) => {
|
2017-01-26 22:57:43 +03:00
|
|
|
resolve(); // OK to leave out arg, same as resolve(undefined)
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2017-01-04 23:24:10 +03:00
|
|
|
var anotherVoidPromise: Promise<void> = Promise.resolve();
|
|
|
|
resolve(anotherVoidPromise);
|
|
|
|
});
|
2016-12-27 21:29:31 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
// simpler repro to show that too few args are fine when expecting void
|
2017-01-24 20:37:01 +03:00
|
|
|
function foo(x: void) {}
|
2017-01-11 18:16:38 +03:00
|
|
|
foo();
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
exports[`test undefined.js 1`] = `
|
|
|
|
"function foo() {
|
|
|
|
var x;
|
|
|
|
x.foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
function bar() {
|
|
|
|
var x:?{ bar():void; };
|
|
|
|
if (x) x.bar();
|
|
|
|
}
|
|
|
|
|
2016-12-28 05:40:04 +03:00
|
|
|
function qux(x?: number, y:string = \"\", z) { }
|
2016-12-23 22:31:38 +03:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2016-12-27 21:29:31 +03:00
|
|
|
function foo() {
|
|
|
|
var x;
|
|
|
|
x.foo();
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
function bar() {
|
2016-12-30 08:01:44 +03:00
|
|
|
var x: ?{ bar(): void };
|
2017-01-15 07:37:13 +03:00
|
|
|
if (x) x.bar();
|
2016-12-27 21:29:31 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-24 20:37:01 +03:00
|
|
|
function qux(x?: number, y: string = \"\", z) {}
|
2017-01-11 18:16:38 +03:00
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
exports[`test undefined2.js 1`] = `
|
|
|
|
"// @flow
|
|
|
|
|
|
|
|
let tests = [
|
|
|
|
function(x: number) {
|
|
|
|
var id;
|
2016-12-28 05:40:04 +03:00
|
|
|
var name = id ? \'John\' : undefined;
|
2016-12-23 22:31:38 +03:00
|
|
|
(name: boolean); // error, string or void
|
|
|
|
|
|
|
|
const bar = [
|
|
|
|
undefined,
|
2016-12-28 05:40:04 +03:00
|
|
|
\'bar\',
|
2016-12-23 22:31:38 +03:00
|
|
|
];
|
|
|
|
(bar[x]: boolean); // error, string or void
|
|
|
|
},
|
|
|
|
|
|
|
|
function(x: number) {
|
2016-12-28 05:40:04 +03:00
|
|
|
var undefined = \'foo\';
|
2016-12-23 22:31:38 +03:00
|
|
|
(undefined: string); // ok
|
|
|
|
|
|
|
|
var x;
|
|
|
|
if (x !== undefined) {
|
|
|
|
x[0]; // should error, could be void
|
|
|
|
}
|
|
|
|
|
|
|
|
const bar = [
|
|
|
|
undefined,
|
2016-12-28 05:40:04 +03:00
|
|
|
\'bar\',
|
2016-12-23 22:31:38 +03:00
|
|
|
];
|
|
|
|
(bar[x]: boolean); // error, string only
|
|
|
|
},
|
|
|
|
];
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
// @flow
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
let tests = [
|
|
|
|
function(x: number) {
|
|
|
|
var id;
|
2017-01-05 20:32:56 +03:00
|
|
|
var name = id ? \"John\" : undefined;
|
2017-01-26 22:57:43 +03:00
|
|
|
(name: boolean); // error, string or void
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2017-01-24 22:38:12 +03:00
|
|
|
const bar = [undefined, \"bar\"];
|
2017-01-10 05:49:06 +03:00
|
|
|
(bar[x]: boolean); // error, string or void
|
2016-12-23 22:31:38 +03:00
|
|
|
},
|
|
|
|
function(x: number) {
|
2016-12-28 05:40:04 +03:00
|
|
|
var undefined = \"foo\";
|
2017-01-26 22:57:43 +03:00
|
|
|
(undefined: string); // ok
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
var x;
|
|
|
|
if (x !== undefined) {
|
2017-01-10 05:49:06 +03:00
|
|
|
x[0]; // should error, could be void
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-24 22:38:12 +03:00
|
|
|
const bar = [undefined, \"bar\"];
|
2017-01-10 05:49:06 +03:00
|
|
|
(bar[x]: boolean); // error, string only
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-11 18:16:38 +03:00
|
|
|
];
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|