I find it weird to put `{}` together. So I figured I would change it to have an empty line and ask for feedback :)

Beware: most of the test cases are not representative of real code, you almost never define blocks with no content in practice.
118 lines
2.4 KiB
Plaintext
118 lines
2.4 KiB
Plaintext
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();
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
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();
|
|
"
|
|
`;
|
|
|
|
exports[`test undefined.js 1`] = `
|
|
"function foo() {
|
|
var x;
|
|
x.foo();
|
|
}
|
|
|
|
function bar() {
|
|
var x:?{ bar():void; };
|
|
if (x) x.bar();
|
|
}
|
|
|
|
function qux(x?: number, y:string = \"\", z) { }
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
function foo() {
|
|
var x;
|
|
x.foo();
|
|
}
|
|
|
|
function bar() {
|
|
var x: ?{ bar(): void };
|
|
if (x) x.bar();
|
|
}
|
|
|
|
function qux(x?: number, y: string = \"\", z) {
|
|
}
|
|
"
|
|
`;
|
|
|
|
exports[`test undefined2.js 1`] = `
|
|
"// @flow
|
|
|
|
let tests = [
|
|
function(x: number) {
|
|
var id;
|
|
var name = id ? \'John\' : undefined;
|
|
(name: boolean); // error, string or void
|
|
|
|
const bar = [
|
|
undefined,
|
|
\'bar\',
|
|
];
|
|
(bar[x]: boolean); // error, string or void
|
|
},
|
|
|
|
function(x: number) {
|
|
var undefined = \'foo\';
|
|
(undefined: string); // ok
|
|
|
|
var x;
|
|
if (x !== undefined) {
|
|
x[0]; // should error, could be void
|
|
}
|
|
|
|
const bar = [
|
|
undefined,
|
|
\'bar\',
|
|
];
|
|
(bar[x]: boolean); // error, string only
|
|
},
|
|
];
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// @flow
|
|
|
|
let tests = [
|
|
function(x: number) {
|
|
var id;
|
|
var name = id ? \"John\" : undefined;
|
|
(name: boolean);
|
|
// error, string or void
|
|
const bar = [ undefined, \"bar\" ];
|
|
(bar[x]: boolean); // error, string or void
|
|
},
|
|
function(x: number) {
|
|
var undefined = \"foo\";
|
|
(undefined: string);
|
|
// ok
|
|
var x;
|
|
if (x !== undefined) {
|
|
x[0]; // should error, could be void
|
|
}
|
|
|
|
const bar = [ undefined, \"bar\" ];
|
|
(bar[x]: boolean); // error, string only
|
|
}
|
|
];
|
|
"
|
|
`;
|