parent
e3b41dd6ca
commit
d2d6def9be
|
@ -769,7 +769,7 @@ function genericPrintNoParens(path, options, print) {
|
|||
|
||||
var args = n.arguments;
|
||||
|
||||
if (args && args.length > 0) {
|
||||
if (args) {
|
||||
parts.push(printArgumentsList(path, options, print));
|
||||
}
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ function foo() {
|
|||
let myClassInstance: MyClass = mk();
|
||||
// ok (no confusion across scopes)
|
||||
function mk() {
|
||||
return new MyClass;
|
||||
return new MyClass();
|
||||
}
|
||||
|
||||
class MyClass {} // looked up above
|
||||
|
|
|
@ -89,7 +89,7 @@ arr[day] = 0;
|
|||
(arr[day]: string); // error: number ~> string
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
var arr = [];
|
||||
var day = new Date;
|
||||
var day = new Date();
|
||||
|
||||
// Date instances are numeric (see Flow_js.numeric) and thus can index into
|
||||
// arrays.
|
||||
|
|
|
@ -182,7 +182,7 @@ class C {
|
|||
var e = async function() {};
|
||||
var et = async function<T>(a: T) {};
|
||||
|
||||
var n = new async function() {};
|
||||
var n = new async function() {}();
|
||||
|
||||
var o = { async m() {} };
|
||||
var ot = { async m<T>(a: T) {} };
|
||||
|
@ -484,7 +484,7 @@ var et = async function<T>(a: T) {
|
|||
|
||||
var n = new async function() {
|
||||
await 1;
|
||||
};
|
||||
}();
|
||||
|
||||
var o = {
|
||||
async m() {
|
||||
|
|
|
@ -876,11 +876,11 @@ function f5() {
|
|||
//
|
||||
var x: C;
|
||||
// ok
|
||||
var y = new C;
|
||||
var y = new C();
|
||||
// error: let ref before decl from value position
|
||||
class C {}
|
||||
|
||||
var z: C = new C;
|
||||
var z: C = new C();
|
||||
// ok
|
||||
// --- vars ---
|
||||
// it\'s possible to annotate a var with a non-maybe type,
|
||||
|
|
|
@ -70,7 +70,7 @@ for (let [x, y]: [number, number] of a.entries()) {} // incorrect
|
|||
/* @flow */
|
||||
|
||||
// constructor
|
||||
const a: FormData = new FormData;
|
||||
const a: FormData = new FormData();
|
||||
// correct
|
||||
new FormData(\"\");
|
||||
// incorrect
|
||||
|
@ -116,11 +116,11 @@ a.set(\"bar\", new File([], \"q\"), \"x\");
|
|||
// correct
|
||||
a.set(\"bar\", new File([], \"q\"), 2);
|
||||
// incorrect
|
||||
a.set(\"bar\", new Blob);
|
||||
a.set(\"bar\", new Blob());
|
||||
// correct
|
||||
a.set(\"bar\", new Blob, \"x\");
|
||||
a.set(\"bar\", new Blob(), \"x\");
|
||||
// correct
|
||||
a.set(\"bar\", new Blob, 2);
|
||||
a.set(\"bar\", new Blob(), 2);
|
||||
// incorrect
|
||||
// append
|
||||
a.append(\"foo\", \"bar\");
|
||||
|
@ -139,11 +139,11 @@ a.append(\"bar\", new File([], \"q\"), \"x\");
|
|||
// correct
|
||||
a.append(\"bar\", new File([], \"q\"), 2);
|
||||
// incorrect
|
||||
a.append(\"bar\", new Blob);
|
||||
a.append(\"bar\", new Blob());
|
||||
// correct
|
||||
a.append(\"bar\", new Blob, \"x\");
|
||||
a.append(\"bar\", new Blob(), \"x\");
|
||||
// correct
|
||||
a.append(\"bar\", new Blob, 2);
|
||||
a.append(\"bar\", new Blob(), 2);
|
||||
// incorrect
|
||||
// delete
|
||||
a.delete(\"xx\");
|
||||
|
@ -218,7 +218,7 @@ new MutationObserver((arr: Array<MutationRecord>) => true);
|
|||
// correct
|
||||
new MutationObserver(() => {});
|
||||
// correct
|
||||
new MutationObserver;
|
||||
new MutationObserver();
|
||||
// incorrect
|
||||
new MutationObserver(42);
|
||||
// incorrect
|
||||
|
|
|
@ -67,7 +67,7 @@ function example<T: { x: number }>(o: T): T {
|
|||
var obj1: { x: number, y: string } = example({ x: 0, y: \"\" });
|
||||
var obj2: { x: number } = example({ x: 0 });
|
||||
|
||||
var c: C<string> = new C;
|
||||
var c: C<string> = new C();
|
||||
// error, since T = string is incompatible with number
|
||||
var q: number = c.qux(0);
|
||||
/* 2 more errors, since argument U = number is incompatible with T = string, and
|
||||
|
|
|
@ -32,7 +32,7 @@ function f() {
|
|||
}
|
||||
|
||||
var Foo = require(\"./genericfoo\");
|
||||
var foo = new Foo;
|
||||
var foo = new Foo();
|
||||
function g() {
|
||||
var foo1 = foo.map(function() {
|
||||
return \"...\";
|
||||
|
@ -60,7 +60,7 @@ class Foo<T> {
|
|||
return this;
|
||||
}
|
||||
map<U>(callbackfn: () => U): Foo<U> {
|
||||
return new Foo;
|
||||
return new Foo();
|
||||
}
|
||||
set(x: T): void {}
|
||||
get(): T {
|
||||
|
|
|
@ -88,11 +88,11 @@ class B extends A {
|
|||
B.qux(0); // error
|
||||
}
|
||||
static create(): A {
|
||||
return new this;
|
||||
return new this();
|
||||
}
|
||||
|
||||
static badCreate(): number {
|
||||
return new this; // error B ~> number
|
||||
return new this(); // error B ~> number
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ class C<X> {
|
|||
static x: X;
|
||||
static bar(x: X) {}
|
||||
static create(): C<*> {
|
||||
return new this;
|
||||
return new this();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ class D extends C<string> {
|
|||
}
|
||||
|
||||
var d: C<*> = D.create();
|
||||
(new A: typeof A);
|
||||
(new A(): typeof A);
|
||||
(B: typeof A);
|
||||
|
||||
class E {
|
||||
|
|
|
@ -26,8 +26,8 @@ var I = require(\"./test.js\");
|
|||
|
||||
class C extends I.A {}
|
||||
|
||||
var x: I.A = new C;
|
||||
var y: I.B = new C;"
|
||||
var x: I.A = new C();
|
||||
var y: I.B = new C();"
|
||||
`;
|
||||
|
||||
exports[`test test3.js 1`] = `
|
||||
|
@ -42,7 +42,7 @@ class A<X, Y, Z> {}
|
|||
class B extends A<string, number, boolean> {}
|
||||
class C<X, Y, Z> extends B {}
|
||||
|
||||
var c: C<number, string, Array<boolean>> = new C;
|
||||
var c: C<number, string, Array<boolean>> = new C();
|
||||
// none of the type args matter
|
||||
var a: A<string, number, Array<boolean>> = c; // the third type arg is incorrect"
|
||||
`;
|
||||
|
@ -70,7 +70,7 @@ function foo<X>(c: C<X>, x: X) {}
|
|||
|
||||
type O = { f: number };
|
||||
|
||||
foo((new C: C<O>), { f_: 0 });
|
||||
foo((new C(): C<O>), { f_: 0 });
|
||||
|
||||
class D extends C<O> {
|
||||
bar() {
|
||||
|
@ -78,5 +78,5 @@ class D extends C<O> {
|
|||
}
|
||||
}
|
||||
|
||||
foo(new D, { f_: 0 });"
|
||||
foo(new D(), { f_: 0 });"
|
||||
`;
|
||||
|
|
|
@ -13,14 +13,14 @@ function bar(x: Class<B>): B {
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class A {}
|
||||
function foo(x: Class<A>): A {
|
||||
return new x; // OK
|
||||
return new x(); // OK
|
||||
}
|
||||
|
||||
class B {
|
||||
constructor(_: any) {}
|
||||
}
|
||||
function bar(x: Class<B>): B {
|
||||
return new x; // error (too few args)
|
||||
return new x(); // error (too few args)
|
||||
}"
|
||||
`;
|
||||
|
||||
|
@ -49,9 +49,9 @@ class A {}
|
|||
class B extends A {}
|
||||
class C {}
|
||||
|
||||
check(B, new A);
|
||||
check(A, new B);
|
||||
check(C, new A);
|
||||
check(C, new B);
|
||||
check(B, new C);"
|
||||
check(B, new A());
|
||||
check(A, new B());
|
||||
check(C, new A());
|
||||
check(C, new B());
|
||||
check(B, new C());"
|
||||
`;
|
||||
|
|
|
@ -26,7 +26,7 @@ var A = require(\"./A\");
|
|||
|
||||
class B extends A {}
|
||||
|
||||
let b = new B;
|
||||
let b = new B();
|
||||
(b.foo: number);
|
||||
// error, number !~> function
|
||||
module.exports = B;"
|
||||
|
@ -50,7 +50,7 @@ class C extends B {
|
|||
foo(x: string): void {}
|
||||
}
|
||||
|
||||
let c = new C;
|
||||
let c = new C();
|
||||
(c.foo: number);
|
||||
// error, number !~> function
|
||||
module.exports = C;"
|
||||
|
@ -63,7 +63,7 @@ new E().x
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class D {}
|
||||
class E {}
|
||||
new E.x;"
|
||||
new E().x;"
|
||||
`;
|
||||
|
||||
exports[`test class_shapes.js 1`] = `
|
||||
|
@ -120,7 +120,7 @@ class TestClass {
|
|||
c: ?string;
|
||||
}
|
||||
|
||||
var x = new TestClass;
|
||||
var x = new TestClass();
|
||||
|
||||
x.a;
|
||||
// ok
|
||||
|
@ -144,7 +144,7 @@ class Test2Class extends Test2Superclass {
|
|||
b: number; // conflicts with cast to Foo
|
||||
}
|
||||
|
||||
var z = new Test2Class;
|
||||
var z = new Test2Class();
|
||||
var w: Foo = z;"
|
||||
`;
|
||||
|
||||
|
@ -183,33 +183,33 @@ var alias2: Alias = _Alias.factory(); // error: bad pun
|
|||
var Bar = class Foo {
|
||||
static factory(): Foo {
|
||||
// OK: Foo is a type in this scope
|
||||
return new Foo; // OK: Foo is a runtime binding in this scope
|
||||
return new Foo(); // OK: Foo is a runtime binding in this scope
|
||||
}
|
||||
};
|
||||
|
||||
var bar1: Bar = new Bar;
|
||||
var bar1: Bar = new Bar();
|
||||
// OK
|
||||
var bar2: Bar = Bar.factory();
|
||||
// OK
|
||||
// NB: Don\'t write expected errors using Foo to avoid error collapse hiding an
|
||||
// unexpected failure in the above code.
|
||||
var B = class Baz {};
|
||||
var b = new Baz;
|
||||
var b = new Baz();
|
||||
// error: Baz is not a runtime binding in this scope
|
||||
var C = class Qux {};
|
||||
var c: Qux = new C;
|
||||
var c: Qux = new C();
|
||||
// error: Qux is not a type in this scope
|
||||
// OK: anon classes create no binding, but can be bound manually
|
||||
var Anon = class {};
|
||||
var anon: Anon = new Anon;
|
||||
var anon: Anon = new Anon();
|
||||
|
||||
class Alias {}
|
||||
var _Alias = class Alias {
|
||||
static factory(): Alias {
|
||||
return new Alias;
|
||||
return new Alias();
|
||||
}
|
||||
};
|
||||
var alias1: Alias = new _Alias;
|
||||
var alias1: Alias = new _Alias();
|
||||
// error: bad pun
|
||||
var alias2: Alias = _Alias.factory(); // error: bad pun"
|
||||
`;
|
||||
|
|
|
@ -85,7 +85,7 @@ class C {
|
|||
_p: string;
|
||||
}
|
||||
|
||||
module.exports = new C;"
|
||||
module.exports = new C();"
|
||||
`;
|
||||
|
||||
exports[`test commonjs_import.js 1`] = `
|
||||
|
|
|
@ -60,16 +60,16 @@ var y2: string = Foo2.y; // error, found boolean instead of string
|
|||
var z2: string = new Foo2().m();
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
var Foo = require(\"./constructors\").Foo;
|
||||
var x: string = new Foo.x;
|
||||
var x: string = new Foo().x;
|
||||
// error, found number instead of string
|
||||
var y: string = Foo.y;
|
||||
// error, found number instead of string
|
||||
var z: string = new Foo.m();
|
||||
var z: string = new Foo().m();
|
||||
|
||||
var Foo2 = require(\"./constructors\").Foo2;
|
||||
var x2: string = new Foo2.x;
|
||||
var x2: string = new Foo2().x;
|
||||
// error, found boolean instead of string
|
||||
var y2: string = Foo2.y;
|
||||
// error, found boolean instead of string
|
||||
var z2: string = new Foo2.m();"
|
||||
var z2: string = new Foo2().m();"
|
||||
`;
|
||||
|
|
|
@ -49,7 +49,7 @@ let tests = [
|
|||
let tests = [
|
||||
// constructor
|
||||
function() {
|
||||
new Boolean;
|
||||
new Boolean();
|
||||
new Boolean(0);
|
||||
new Boolean(-0);
|
||||
new Boolean(null);
|
||||
|
@ -128,11 +128,11 @@ function* generator(): Iterable<[string, number]> {
|
|||
let tests = [
|
||||
// good constructors
|
||||
function() {
|
||||
let w = new Map;
|
||||
let w = new Map();
|
||||
let x = new Map(null);
|
||||
let y = new Map([ [ \"foo\", 123 ] ]);
|
||||
let z = new Map(generator());
|
||||
let a: Map<string, number> = new Map;
|
||||
let a: Map<string, number> = new Map();
|
||||
let b: Map<string, number> = new Map([ [ \"foo\", 123 ] ]);
|
||||
let c: Map<string, number> = new Map(generator());
|
||||
},
|
||||
|
@ -254,7 +254,7 @@ let ws5 = new WeakSet(numbers()); // error, must be objects
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// @flow
|
||||
|
||||
let ws = new WeakSet;
|
||||
let ws = new WeakSet();
|
||||
let obj: Object = {};
|
||||
let dict: { foo: string } = { foo: \"bar\" };
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ class NVerbose<E, I: E> {
|
|||
}
|
||||
}
|
||||
|
||||
var nv: NVerbose<number, *> = new NVerbose;
|
||||
var nv: NVerbose<number, *> = new NVerbose();
|
||||
nv.x = [ 0 ];
|
||||
(nv.x[0]: string);
|
||||
// error
|
||||
|
|
|
@ -34,7 +34,7 @@ var x: string = d.getTime();
|
|||
var y: number = d;
|
||||
|
||||
// valid constructors
|
||||
new Date;
|
||||
new Date();
|
||||
new Date(1234567890);
|
||||
new Date(\"2015/06/18\");
|
||||
new Date(2015, 6);
|
||||
|
|
|
@ -6,7 +6,7 @@ export function foo(): Implementation { return new Implementation; }
|
|||
/* @providesModule A */
|
||||
class Implementation {}
|
||||
export function foo(): Implementation {
|
||||
return new Implementation;
|
||||
return new Implementation();
|
||||
}"
|
||||
`;
|
||||
|
||||
|
@ -25,7 +25,7 @@ module.exports.fun = (): Implementation => new Implementation;
|
|||
*/
|
||||
|
||||
class Implementation {}
|
||||
module.exports.fun = (): Implementation => new Implementation;"
|
||||
module.exports.fun = (): Implementation => new Implementation();"
|
||||
`;
|
||||
|
||||
exports[`test ExplicitProvidesModuleSameName.js 1`] = `
|
||||
|
@ -43,7 +43,7 @@ module.exports.fun = (): Implementation => new Implementation;
|
|||
*/
|
||||
|
||||
class Implementation {}
|
||||
module.exports.fun = (): Implementation => new Implementation;"
|
||||
module.exports.fun = (): Implementation => new Implementation();"
|
||||
`;
|
||||
|
||||
exports[`test ImplicitProvidesModule.js 1`] = `
|
||||
|
@ -61,7 +61,7 @@ module.exports.fun = (): Implementation => new Implementation;
|
|||
*/
|
||||
|
||||
class Implementation {}
|
||||
module.exports.fun = (): Implementation => new Implementation;"
|
||||
module.exports.fun = (): Implementation => new Implementation();"
|
||||
`;
|
||||
|
||||
exports[`test md5.js 1`] = `
|
||||
|
|
|
@ -3,5 +3,5 @@ exports[`test min.js 1`] = `
|
|||
module.exports.fun = (): Implementation => new Implementation;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class Implementation {}
|
||||
module.exports.fun = (): Implementation => new Implementation;"
|
||||
module.exports.fun = (): Implementation => new Implementation();"
|
||||
`;
|
||||
|
|
|
@ -4,7 +4,7 @@ export function foo(): Implementation { return new Implementation; }
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class Implementation {}
|
||||
export function foo(): Implementation {
|
||||
return new Implementation;
|
||||
return new Implementation();
|
||||
}"
|
||||
`;
|
||||
|
||||
|
|
|
@ -908,22 +908,22 @@ import {doesntExist2} from \"CommonJS_Clobbering_Class\";
|
|||
import {staticNumber1, baseProp, childProp} from \"CommonJS_Clobbering_Class\";
|
||||
// Error
|
||||
import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\";
|
||||
new CJS_Clobb_Class;
|
||||
new CJS_Clobb_Class.doesntExist;
|
||||
new CJS_Clobb_Class();
|
||||
new CJS_Clobb_Class().doesntExist;
|
||||
// Error: Class has no \`doesntExist\` property
|
||||
var h1: number = CJS_Clobb_Class.staticNumber2();
|
||||
var h2: string = CJS_Clobb_Class.staticNumber2();
|
||||
// Error: number ~> string
|
||||
var h3: number = new CJS_Clobb_Class.instNumber1();
|
||||
var h4: string = new CJS_Clobb_Class.instNumber1();
|
||||
var h3: number = new CJS_Clobb_Class().instNumber1();
|
||||
var h4: string = new CJS_Clobb_Class().instNumber1();
|
||||
// Error: number ~> string
|
||||
import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\";
|
||||
new CJS_Clobb_Class_NS;
|
||||
new CJS_Clobb_Class_NS();
|
||||
// Error: Namespace object isn\'t constructable
|
||||
var i1: number = CJS_Clobb_Class_NS.staticNumber3();
|
||||
// Error: Class statics not copied to Namespace object
|
||||
var i2: number = new CJS_Clobb_Class_NS.default.instNumber2();
|
||||
var i3: string = new CJS_Clobb_Class_NS.default.instNumber2();
|
||||
var i2: number = new CJS_Clobb_Class_NS.default().instNumber2();
|
||||
var i3: string = new CJS_Clobb_Class_NS.default().instNumber2();
|
||||
// Error: number ~> string
|
||||
// =================================== //
|
||||
// == CommonJS Named Exports -> ES6 == //
|
||||
|
@ -964,8 +964,8 @@ var o1: number = ES6_Def_NamedFunc1();
|
|||
var o2: string = ES6_Def_NamedFunc1();
|
||||
// Error: number ~> string
|
||||
import ES6_Def_NamedClass1 from \"ES6_Default_NamedClass1\";
|
||||
var q1: number = new ES6_Def_NamedClass1.givesANum();
|
||||
var q2: string = new ES6_Def_NamedClass1.givesANum();
|
||||
var q1: number = new ES6_Def_NamedClass1().givesANum();
|
||||
var q2: string = new ES6_Def_NamedClass1().givesANum();
|
||||
// Error: number ~> string
|
||||
////////////////////////////
|
||||
// == ES6 Named -> ES6 == //
|
||||
|
@ -996,8 +996,8 @@ var v1: number = givesANumber();
|
|||
var v2: string = givesANumber();
|
||||
// Error: number ~> string
|
||||
import {NumberGenerator} from \"ES6_Named1\";
|
||||
var w1: number = new NumberGenerator.givesANumber();
|
||||
var w2: string = new NumberGenerator.givesANumber();
|
||||
var w1: number = new NumberGenerator().givesANumber();
|
||||
var w2: string = new NumberGenerator().givesANumber();
|
||||
// Error: number ~> string
|
||||
import {varDeclNumber1, varDeclNumber2} from \"ES6_Named1\";
|
||||
var x1: number = varDeclNumber1;
|
||||
|
@ -1032,8 +1032,8 @@ var ae1: number = ES6_Def_NamedFunc2();
|
|||
var ae2: string = ES6_Def_NamedFunc2();
|
||||
// Error: number ~> string
|
||||
var ES6_Def_NamedClass2 = require(\"ES6_Default_NamedClass2\").default;
|
||||
var ag1: number = new ES6_Def_NamedClass2.givesANum();
|
||||
var ag2: string = new ES6_Def_NamedClass2.givesANum();
|
||||
var ag1: number = new ES6_Def_NamedClass2().givesANum();
|
||||
var ag2: string = new ES6_Def_NamedClass2().givesANum();
|
||||
// Error: number ~> string
|
||||
/////////////////////////////////
|
||||
// == ES6 Named -> CommonJS == //
|
||||
|
@ -1059,8 +1059,8 @@ var ak1: number = givesANumber2();
|
|||
var ak2: string = givesANumber2();
|
||||
// Error: number ~> string
|
||||
var NumberGenerator2 = require(\"ES6_Named2\").NumberGenerator2;
|
||||
var al1: number = new NumberGenerator2.givesANumber();
|
||||
var al2: string = new NumberGenerator2.givesANumber();
|
||||
var al1: number = new NumberGenerator2().givesANumber();
|
||||
var al2: string = new NumberGenerator2().givesANumber();
|
||||
// Error: number ~> string
|
||||
var varDeclNumber3 = require(\"ES6_Named2\").varDeclNumber3;
|
||||
var varDeclNumber4 = require(\"ES6_Named2\").varDeclNumber4;
|
||||
|
|
|
@ -372,7 +372,7 @@ class Child extends Base {
|
|||
childprop2: number;
|
||||
}
|
||||
|
||||
var { baseprop1, childprop1, ...others } = new Child;
|
||||
var { baseprop1, childprop1, ...others } = new Child();
|
||||
|
||||
var bp1: number = baseprop1;
|
||||
var bp1_err: string = baseprop1;
|
||||
|
|
|
@ -411,11 +411,11 @@ function unsound_dict_has_every_key(o: { [k: string]: X }) {
|
|||
|
||||
// As with any object type, we can assign subtypes to properties.
|
||||
function set_prop_covariant(o: { [k: string]: B }) {
|
||||
o.p = new A;
|
||||
o.p = new A();
|
||||
// error, A ~> B
|
||||
o.p = new B;
|
||||
o.p = new B();
|
||||
// ok
|
||||
o.p = new C; // ok
|
||||
o.p = new C(); // ok
|
||||
}
|
||||
|
||||
// This isn\'t specific behavior to dictionaries, but for completeness...
|
||||
|
@ -472,7 +472,7 @@ function unsound_string_conversion_alias_declared_prop(
|
|||
function unification_dict_values_invariant(x: Array<{ [k: string]: B }>) {
|
||||
let a: Array<{ [k: string]: A }> = x;
|
||||
// error
|
||||
a[0].p = new A;
|
||||
a[0].p = new A();
|
||||
// in[0].p no longer B
|
||||
let b: Array<{ [k: string]: B }> = x;
|
||||
// ok
|
||||
|
@ -484,7 +484,7 @@ function unification_dict_values_invariant(x: Array<{ [k: string]: B }>) {
|
|||
function subtype_dict_values_invariant(x: { [k: string]: B }) {
|
||||
let a: { [k: string]: A } = x;
|
||||
// error
|
||||
a.p = new A;
|
||||
a.p = new A();
|
||||
// x[0].p no longer B
|
||||
let b: { [k: string]: B } = x;
|
||||
// ok
|
||||
|
@ -495,30 +495,30 @@ function subtype_dict_values_invariant(x: { [k: string]: B }) {
|
|||
|
||||
function subtype_dict_values_fresh_exception() {
|
||||
let a: { [k: string]: A } = {
|
||||
a: new A,
|
||||
a: new A(),
|
||||
// ok, A == A
|
||||
b: new B,
|
||||
b: new B(),
|
||||
// ok, B <: A
|
||||
// ok, C <: A
|
||||
c: new C
|
||||
c: new C()
|
||||
};
|
||||
|
||||
let b: { [k: string]: B } = {
|
||||
a: new A,
|
||||
a: new A(),
|
||||
// error, A not <: B
|
||||
b: new B,
|
||||
b: new B(),
|
||||
// ok, B == B
|
||||
// ok, C <: A
|
||||
c: new C
|
||||
c: new C()
|
||||
};
|
||||
|
||||
let c: { [k: string]: C } = {
|
||||
a: new A,
|
||||
a: new A(),
|
||||
// error, A not <: C
|
||||
b: new B,
|
||||
b: new B(),
|
||||
// error, A not <: C
|
||||
// ok, C == C
|
||||
c: new C
|
||||
c: new C()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -548,7 +548,7 @@ function unification_mix_with_declared_props_invariant_l(
|
|||
) {
|
||||
let a: Array<{ [k: string]: B, p: A }> = x;
|
||||
// error: A ~> B
|
||||
a[0].p = new A;
|
||||
a[0].p = new A();
|
||||
// x[0].p no longer B
|
||||
let b: Array<{ [k: string]: B, p: B }> = x;
|
||||
// ok
|
||||
|
@ -564,7 +564,7 @@ function unification_mix_with_declared_props_invariant_r(
|
|||
) {
|
||||
let a: Array<{ [k: string]: A }> = xa;
|
||||
// error
|
||||
a[0].p = new A;
|
||||
a[0].p = new A();
|
||||
// xa[0].p no longer B
|
||||
let b: Array<{ [k: string]: B }> = xb;
|
||||
// ok
|
||||
|
@ -576,7 +576,7 @@ function unification_mix_with_declared_props_invariant_r(
|
|||
function subtype_mix_with_declared_props_invariant_l(x: { [k: string]: B }) {
|
||||
let a: { [k: string]: B, p: A } = x;
|
||||
// error: A ~> B
|
||||
a.p = new A;
|
||||
a.p = new A();
|
||||
// x.p no longer B
|
||||
let b: { [k: string]: B, p: B } = x;
|
||||
// ok
|
||||
|
@ -592,7 +592,7 @@ function subtype_mix_with_declared_props_invariant_r(
|
|||
) {
|
||||
let a: { [k: string]: A } = xa;
|
||||
// error
|
||||
a.p = new A;
|
||||
a.p = new A();
|
||||
// xa.p no longer B
|
||||
let b: { [k: string]: B } = xb;
|
||||
// ok
|
||||
|
@ -616,7 +616,7 @@ function unification_obj_to_dict(
|
|||
function subtype_dict_to_obj(x: { [k: string]: B }) {
|
||||
let a: { p: A } = x;
|
||||
// error
|
||||
a.p = new A;
|
||||
a.p = new A();
|
||||
// x.p no longer B
|
||||
let b: { p: B } = x;
|
||||
// ok
|
||||
|
@ -628,7 +628,7 @@ function subtype_dict_to_obj(x: { [k: string]: B }) {
|
|||
function subtype_obj_to_dict(x: { p: B }) {
|
||||
let a: { [k: string]: A } = x;
|
||||
// error
|
||||
a.p = new A;
|
||||
a.p = new A();
|
||||
// x.p no longer B
|
||||
let b: { [k: string]: B } = x;
|
||||
|
||||
|
|
|
@ -297,14 +297,14 @@ let listener: EventListener = function(event: Event): void {};
|
|||
let tests = [
|
||||
// attachEvent
|
||||
function() {
|
||||
let target = new EventTarget;
|
||||
let target = new EventTarget();
|
||||
(target.attachEvent(\"foo\", listener): void);
|
||||
// invalid, may be undefined
|
||||
(target.attachEvent && target.attachEvent(\"foo\", listener): void); // valid
|
||||
},
|
||||
// detachEvent
|
||||
function() {
|
||||
let target = new EventTarget;
|
||||
let target = new EventTarget();
|
||||
(target.detachEvent(\"foo\", listener): void);
|
||||
// invalid, may be undefined
|
||||
(target.detachEvent && target.detachEvent(\"foo\", listener): void); // valid
|
||||
|
@ -335,7 +335,7 @@ let tests = [
|
|||
let tests = [
|
||||
// arcTo
|
||||
function() {
|
||||
let path = new Path2D;
|
||||
let path = new Path2D();
|
||||
(path.arcTo(0, 0, 0, 0, 10): void);
|
||||
// valid
|
||||
(path.arcTo(0, 0, 0, 0, 10, 20, 5): void);
|
||||
|
|
|
@ -40,7 +40,7 @@ class C1 {
|
|||
m() {}
|
||||
}
|
||||
|
||||
new C1.m();
|
||||
new C1().m();
|
||||
|
||||
class C2 {
|
||||
get m() {
|
||||
|
@ -49,14 +49,14 @@ class C2 {
|
|||
m() {}
|
||||
}
|
||||
|
||||
new C2.m();
|
||||
new C2().m();
|
||||
|
||||
class C3 {
|
||||
set m(x) {}
|
||||
m() {}
|
||||
}
|
||||
|
||||
new C3.m();
|
||||
new C3().m();
|
||||
|
||||
class C4 {
|
||||
get m() {
|
||||
|
@ -65,7 +65,7 @@ class C4 {
|
|||
set m(x: number) {}
|
||||
}
|
||||
|
||||
new C4.m = new C4.m - 42;
|
||||
new C4().m = new C4().m - 42;
|
||||
|
||||
class C5 {
|
||||
m() {}
|
||||
|
@ -75,5 +75,5 @@ class C5 {
|
|||
set m(x: number) {}
|
||||
}
|
||||
|
||||
new C5.m = new C5.m - 42;"
|
||||
new C5().m = new C5().m - 42;"
|
||||
`;
|
||||
|
|
|
@ -17,7 +17,7 @@ var s3 = tag2 \`la la la\`;
|
|||
(s3.foo: number); // error: string ~> number
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class A {}
|
||||
var a = new A;
|
||||
var a = new A();
|
||||
var s1 = \`l\${a.x}r\`;
|
||||
// error: no prop x in A
|
||||
function tag(strings, ...values) {
|
||||
|
|
|
@ -245,7 +245,7 @@ export default class Foo {
|
|||
// Regression test for https://github.com/facebook/flow/issues/511
|
||||
//
|
||||
// Default-exported class should also be available in local scope
|
||||
new Foo;"
|
||||
new Foo();"
|
||||
`;
|
||||
|
||||
exports[`test ES6_Default_NamedClass2.js 1`] = `
|
||||
|
@ -1011,22 +1011,22 @@ import {doesntExist2} from \"CommonJS_Clobbering_Class\";
|
|||
import {staticNumber1, baseProp, childProp} from \"CommonJS_Clobbering_Class\";
|
||||
// Error
|
||||
import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\";
|
||||
new CJS_Clobb_Class;
|
||||
new CJS_Clobb_Class.doesntExist;
|
||||
new CJS_Clobb_Class();
|
||||
new CJS_Clobb_Class().doesntExist;
|
||||
// Error: Class has no \`doesntExist\` property
|
||||
var h1: number = CJS_Clobb_Class.staticNumber2();
|
||||
var h2: string = CJS_Clobb_Class.staticNumber2();
|
||||
// Error: number ~> string
|
||||
var h3: number = new CJS_Clobb_Class.instNumber1();
|
||||
var h4: string = new CJS_Clobb_Class.instNumber1();
|
||||
var h3: number = new CJS_Clobb_Class().instNumber1();
|
||||
var h4: string = new CJS_Clobb_Class().instNumber1();
|
||||
// Error: number ~> string
|
||||
import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\";
|
||||
new CJS_Clobb_Class_NS;
|
||||
new CJS_Clobb_Class_NS();
|
||||
// Error: Namespace object isn\'t constructable
|
||||
var i1: number = CJS_Clobb_Class_NS.staticNumber3();
|
||||
// Error: Class statics not copied to Namespace object
|
||||
var i2: number = new CJS_Clobb_Class_NS.default.instNumber2();
|
||||
var i3: string = new CJS_Clobb_Class_NS.default.instNumber2();
|
||||
var i2: number = new CJS_Clobb_Class_NS.default().instNumber2();
|
||||
var i3: string = new CJS_Clobb_Class_NS.default().instNumber2();
|
||||
// Error: number ~> string
|
||||
// =================================== //
|
||||
// == CommonJS Named Exports -> ES6 == //
|
||||
|
@ -1067,12 +1067,12 @@ var o1: number = ES6_Def_NamedFunc1();
|
|||
var o2: string = ES6_Def_NamedFunc1();
|
||||
// Error: number ~> string
|
||||
import ES6_Def_AnonClass1 from \"ES6_Default_AnonClass1\";
|
||||
var p1: number = new ES6_Def_AnonClass1.givesANum();
|
||||
var p2: string = new ES6_Def_AnonClass1.givesANum();
|
||||
var p1: number = new ES6_Def_AnonClass1().givesANum();
|
||||
var p2: string = new ES6_Def_AnonClass1().givesANum();
|
||||
// Error: number ~> string
|
||||
import ES6_Def_NamedClass1 from \"ES6_Default_NamedClass1\";
|
||||
var q1: number = new ES6_Def_NamedClass1.givesANum();
|
||||
var q2: string = new ES6_Def_NamedClass1.givesANum();
|
||||
var q1: number = new ES6_Def_NamedClass1().givesANum();
|
||||
var q2: string = new ES6_Def_NamedClass1().givesANum();
|
||||
// Error: number ~> string
|
||||
////////////////////////////
|
||||
// == ES6 Named -> ES6 == //
|
||||
|
@ -1103,8 +1103,8 @@ var v1: number = givesANumber();
|
|||
var v2: string = givesANumber();
|
||||
// Error: number ~> string
|
||||
import {NumberGenerator} from \"ES6_Named1\";
|
||||
var w1: number = new NumberGenerator.givesANumber();
|
||||
var w2: string = new NumberGenerator.givesANumber();
|
||||
var w1: number = new NumberGenerator().givesANumber();
|
||||
var w2: string = new NumberGenerator().givesANumber();
|
||||
// Error: number ~> string
|
||||
import {varDeclNumber1, varDeclNumber2} from \"ES6_Named1\";
|
||||
var x1: number = varDeclNumber1;
|
||||
|
@ -1147,12 +1147,12 @@ var ae1: number = ES6_Def_NamedFunc2();
|
|||
var ae2: string = ES6_Def_NamedFunc2();
|
||||
// Error: number ~> string
|
||||
var ES6_Def_AnonClass2 = require(\"ES6_Default_AnonClass2\").default;
|
||||
var af1: number = new ES6_Def_AnonClass2.givesANum();
|
||||
var af2: string = new ES6_Def_AnonClass2.givesANum();
|
||||
var af1: number = new ES6_Def_AnonClass2().givesANum();
|
||||
var af2: string = new ES6_Def_AnonClass2().givesANum();
|
||||
// Error: number ~> string
|
||||
var ES6_Def_NamedClass2 = require(\"ES6_Default_NamedClass2\").default;
|
||||
var ag1: number = new ES6_Def_NamedClass2.givesANum();
|
||||
var ag2: string = new ES6_Def_NamedClass2.givesANum();
|
||||
var ag1: number = new ES6_Def_NamedClass2().givesANum();
|
||||
var ag2: string = new ES6_Def_NamedClass2().givesANum();
|
||||
// Error: number ~> string
|
||||
/////////////////////////////////
|
||||
// == ES6 Named -> CommonJS == //
|
||||
|
@ -1178,8 +1178,8 @@ var ak1: number = givesANumber2();
|
|||
var ak2: string = givesANumber2();
|
||||
// Error: number ~> string
|
||||
var NumberGenerator2 = require(\"ES6_Named2\").NumberGenerator2;
|
||||
var al1: number = new NumberGenerator2.givesANumber();
|
||||
var al2: string = new NumberGenerator2.givesANumber();
|
||||
var al1: number = new NumberGenerator2().givesANumber();
|
||||
var al2: string = new NumberGenerator2().givesANumber();
|
||||
// Error: number ~> string
|
||||
var varDeclNumber3 = require(\"ES6_Named2\").varDeclNumber3;
|
||||
var varDeclNumber4 = require(\"ES6_Named2\").varDeclNumber4;
|
||||
|
|
|
@ -76,10 +76,10 @@ import {num3} from \"ES\";
|
|||
// Error: number ~> string
|
||||
import {C} from \"ES\";
|
||||
import type {C as CType} from \"ES\";
|
||||
(new C: C);
|
||||
(new C(): C);
|
||||
(42: C);
|
||||
// Error: number ~> C
|
||||
(new C: CType);
|
||||
(new C(): CType);
|
||||
(42: CType);
|
||||
// Error: number ~> CType
|
||||
import {T} from \"ES\";
|
||||
|
|
|
@ -88,7 +88,7 @@ const c = new Headers({ \"Content-Type\", \"image/jpeg\" });
|
|||
// correct
|
||||
const d = new Headers(c);
|
||||
// correct
|
||||
const e: Headers = new Headers;
|
||||
const e: Headers = new Headers();
|
||||
// correct
|
||||
e.append(\"Content-Type\", \"image/jpeg\");
|
||||
// correct
|
||||
|
@ -173,7 +173,7 @@ h.arrayBuffer().then((ab: ArrayBuffer) => ab); // correct
|
|||
h.arrayBuffer().then((ab: Buffer) => ab); // incorrect
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/* @flow */
|
||||
const a: Request = new Request;
|
||||
const a: Request = new Request();
|
||||
// incorrect
|
||||
const b: Request = new Request(\"http://example.org\");
|
||||
// correct
|
||||
|
@ -276,13 +276,13 @@ h.arrayBuffer().then((ab: ArrayBuffer) => ab); // correct
|
|||
h.arrayBuffer().then((ab: Buffer) => ab); // incorrect
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/* @flow */
|
||||
const a: Response = new Response;
|
||||
const a: Response = new Response();
|
||||
// correct
|
||||
const b: Response = new Response(new Blob);
|
||||
const b: Response = new Response(new Blob());
|
||||
// correct
|
||||
const c: Response = new Response(new FormData);
|
||||
const c: Response = new Response(new FormData());
|
||||
// correct
|
||||
const d: Response = new Response(new FormData, { status: 404 });
|
||||
const d: Response = new Response(new FormData(), { status: 404 });
|
||||
// correct
|
||||
const e: Response = new Response(\"responsebody\", { status: \"404\" });
|
||||
// incorrect
|
||||
|
@ -358,7 +358,7 @@ const c = new URLSearchParams({ \"key1\", \"value1\" });
|
|||
// not correct
|
||||
const d = new URLSearchParams(c);
|
||||
// correct
|
||||
const e: URLSearchParams = new URLSearchParams;
|
||||
const e: URLSearchParams = new URLSearchParams();
|
||||
// correct
|
||||
e.append(\"key1\", \"value1\");
|
||||
// correct
|
||||
|
|
|
@ -226,7 +226,7 @@ class GeneratorExamples {
|
|||
}
|
||||
}
|
||||
|
||||
var examples = new GeneratorExamples;
|
||||
var examples = new GeneratorExamples();
|
||||
|
||||
for (var x of examples.infer_stmt()) {
|
||||
(x: string);
|
||||
|
@ -297,7 +297,7 @@ class GeneratorExamples<X> {
|
|||
}
|
||||
}
|
||||
|
||||
var examples = new GeneratorExamples;
|
||||
var examples = new GeneratorExamples();
|
||||
|
||||
for (var x of examples.infer_stmt()) {
|
||||
(x: string);
|
||||
|
|
|
@ -62,7 +62,7 @@ class D<T> {
|
|||
}
|
||||
}
|
||||
|
||||
var d = new D;
|
||||
var d = new D();
|
||||
var o = {};
|
||||
var b = d.m(true, 0, o);
|
||||
var s: string = d.x;
|
||||
|
@ -78,7 +78,7 @@ class E<X> extends C<X> {
|
|||
}
|
||||
}
|
||||
|
||||
var e = new E;
|
||||
var e = new E();
|
||||
// error: too few arguments to inherited constructor
|
||||
var x: string = e.set(0);
|
||||
|
||||
|
@ -91,7 +91,7 @@ class H<Z> extends G<Array<Z>> {
|
|||
}
|
||||
}
|
||||
|
||||
var h1 = new H;
|
||||
var h1 = new H();
|
||||
h1.foo([ \"...\" ]);
|
||||
var h2: F<Array<Array<Array<number>>>> = h1;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ geolocation.clearWatch(id);
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/* @flow */
|
||||
|
||||
var geolocation = new Geolocation;
|
||||
var geolocation = new Geolocation();
|
||||
var id = geolocation.watchPosition(
|
||||
position => {
|
||||
var coords: Coordinates = position.coords;
|
||||
|
|
|
@ -107,7 +107,7 @@ class Foo {
|
|||
set propOverriddenWithSetter(x: string) {}
|
||||
}
|
||||
|
||||
var foo = new Foo;
|
||||
var foo = new Foo();
|
||||
|
||||
// Test getting properties with getters
|
||||
var testGetterNoError1: number = foo.goodGetterNoAnnotation;
|
||||
|
@ -234,12 +234,12 @@ var obj = {
|
|||
return 4;
|
||||
},
|
||||
get exampleOfOrderOfGetterAndSetter(): A {
|
||||
return new A;
|
||||
return new A();
|
||||
},
|
||||
set exampleOfOrderOfGetterAndSetter(x: B) {},
|
||||
set exampleOfOrderOfGetterAndSetterReordered(x: B) {},
|
||||
get exampleOfOrderOfGetterAndSetterReordered(): A {
|
||||
return new A;
|
||||
return new A();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -264,7 +264,7 @@ var testSubtypingGetterAndSetter: number = obj.propWithSubtypingGetterAndSetter;
|
|||
// When building this feature, it was tempting to flow the setter into the
|
||||
// getter and then use either the getter or setter as the type of the property.
|
||||
// This example shows the danger of using the getter\'s type
|
||||
obj.exampleOfOrderOfGetterAndSetter = new C;
|
||||
obj.exampleOfOrderOfGetterAndSetter = new C();
|
||||
// Error C ~> B
|
||||
// And this example shows the danger of using the setter\'s type.
|
||||
var testExampleOrOrderOfGetterAndSetterReordered: number = obj.exampleOfOrderOfGetterAndSetterReordered; // Error A ~> B"
|
||||
|
|
|
@ -20,8 +20,8 @@ class B extends A {
|
|||
}
|
||||
}
|
||||
class C extends A {}
|
||||
var a: A = new B;
|
||||
var a: A = new B();
|
||||
a.foo = function(): C {
|
||||
return new C;
|
||||
return new C();
|
||||
};"
|
||||
`;
|
||||
|
|
|
@ -21,7 +21,7 @@ class ClassFoo3 {
|
|||
return 42;
|
||||
}
|
||||
static givesAFoo3(): ClassFoo3 {
|
||||
return new ClassFoo3;
|
||||
return new ClassFoo3();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,17 +65,17 @@ class ClassFoo4 {
|
|||
class ClassFoo5 {}
|
||||
|
||||
function givesAFoo4(): ClassFoo4 {
|
||||
return new ClassFoo4;
|
||||
return new ClassFoo4();
|
||||
}
|
||||
|
||||
function givesAFoo5(): ClassFoo5 {
|
||||
return new ClassFoo5;
|
||||
return new ClassFoo5();
|
||||
}
|
||||
|
||||
exports.ClassFoo4 = ClassFoo4;
|
||||
exports.ClassFoo5 = ClassFoo5;
|
||||
exports.foo4Inst = new ClassFoo4;
|
||||
exports.foo5Inst = new ClassFoo5;"
|
||||
exports.foo4Inst = new ClassFoo4();
|
||||
exports.foo5Inst = new ClassFoo5();"
|
||||
`;
|
||||
|
||||
exports[`test ExportDefault_Class.js 1`] = `
|
||||
|
@ -101,7 +101,7 @@ class ClassFoo1 {
|
|||
}
|
||||
|
||||
export default ClassFoo1
|
||||
export var foo1Inst = new ClassFoo1;"
|
||||
export var foo1Inst = new ClassFoo1();"
|
||||
`;
|
||||
|
||||
exports[`test ExportNamed_Alias.js 1`] = `
|
||||
|
@ -156,7 +156,7 @@ class ClassFoo2 {
|
|||
}
|
||||
|
||||
export {ClassFoo2}
|
||||
export var foo2Inst = new ClassFoo2;"
|
||||
export var foo2Inst = new ClassFoo2();"
|
||||
`;
|
||||
|
||||
exports[`test ExportsANumber.js 1`] = `
|
||||
|
@ -267,7 +267,7 @@ import {foo1Inst} from \"./ExportDefault_Class\";
|
|||
var a1: ClassFoo1 = foo1Inst;
|
||||
var a2: number = foo1Inst;
|
||||
// Error: ClassFoo1 ~> number
|
||||
new ClassFoo1;
|
||||
new ClassFoo1();
|
||||
// Error: ClassFoo1 is not a value-identifier
|
||||
///////////////////////////////////////////////
|
||||
// == Importing Class Type (Named Export) == //
|
||||
|
@ -278,15 +278,15 @@ import {foo2Inst} from \"./ExportNamed_Class\";
|
|||
var b1: ClassFoo2 = foo2Inst;
|
||||
var b2: number = foo2Inst;
|
||||
// Error: ClassFoo2 ~> number
|
||||
new ClassFoo2;
|
||||
new ClassFoo2();
|
||||
// Error: ClassFoo2 is not a value-identifier
|
||||
/////////////////////////////////////////////////////
|
||||
// == Importing Class Type (CJS Default Export) == //
|
||||
/////////////////////////////////////////////////////
|
||||
import type ClassFoo3T from \"./ExportCJSDefault_Class\";
|
||||
import ClassFoo3 from \"./ExportCJSDefault_Class\";
|
||||
var c1: ClassFoo3T = new ClassFoo3;
|
||||
new ClassFoo3T;
|
||||
var c1: ClassFoo3T = new ClassFoo3();
|
||||
new ClassFoo3T();
|
||||
// Error: ClassFoo3 is not a value-identifier
|
||||
///////////////////////////////////////////////////
|
||||
// == Importing Class Type (CJS Named Export) == //
|
||||
|
@ -297,7 +297,7 @@ import {foo4Inst, foo5Inst} from \"./ExportCJSNamed_Class\";
|
|||
var d1: ClassFoo4 = foo4Inst;
|
||||
var d2: number = foo4Inst;
|
||||
// Error: ClassFoo4 ~> number
|
||||
new ClassFoo4;
|
||||
new ClassFoo4();
|
||||
// Error: ClassFoo4 is not a value-identifier
|
||||
// TODO: this errors correctly, but the message is just \'can\'t resolve name\'
|
||||
var d3: typeof ClassFoo5 = foo5Inst;
|
||||
|
|
|
@ -21,7 +21,7 @@ class ClassFoo3 {
|
|||
return 42;
|
||||
}
|
||||
static givesAFoo3(): ClassFoo3 {
|
||||
return new ClassFoo3;
|
||||
return new ClassFoo3();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -292,9 +292,9 @@ import typeof ClassFoo1T from \"./ExportDefault_Class\";
|
|||
import ClassFoo1 from \"./ExportDefault_Class\";
|
||||
|
||||
var a1: ClassFoo1T = ClassFoo1;
|
||||
var a2: ClassFoo1T = new ClassFoo1;
|
||||
var a2: ClassFoo1T = new ClassFoo1();
|
||||
// Error: ClassFoo1 (inst) ~> ClassFoo1 (class)
|
||||
new ClassFoo1T;
|
||||
new ClassFoo1T();
|
||||
// Error: ClassFoo1T is not bound to a value
|
||||
/////////////////////////////////////////////////
|
||||
// == Importing Class Typeof (Named Export) == //
|
||||
|
@ -303,9 +303,9 @@ import typeof {ClassFoo2 as ClassFoo2T} from \"./ExportNamed_Class\";
|
|||
import {ClassFoo2} from \"./ExportNamed_Class\";
|
||||
|
||||
var b1: ClassFoo2T = ClassFoo2;
|
||||
var b2: ClassFoo2T = new ClassFoo2;
|
||||
var b2: ClassFoo2T = new ClassFoo2();
|
||||
// Error: ClassFoo2 (inst) ~> ClassFoo2 (class)
|
||||
new ClassFoo2T;
|
||||
new ClassFoo2T();
|
||||
// Error: ClassFoo2T is not bound to a value
|
||||
///////////////////////////////////////////////////////
|
||||
// == Importing Class Typeof (CJS Default Export) == //
|
||||
|
@ -314,7 +314,7 @@ import typeof ClassFoo3T from \"./ExportCJSDefault_Class\";
|
|||
import ClassFoo3 from \"./ExportCJSDefault_Class\";
|
||||
|
||||
var c1: ClassFoo3T = ClassFoo3;
|
||||
var c2: ClassFoo3T = new ClassFoo3;
|
||||
var c2: ClassFoo3T = new ClassFoo3();
|
||||
// Error: ClassFoo3 (inst) ~> ClassFoo3 (class)
|
||||
/////////////////////////////////////////////////////
|
||||
// == Importing Class Typeof (CJS Named Export) == //
|
||||
|
@ -323,7 +323,7 @@ import typeof {ClassFoo4 as ClassFoo4T} from \"./ExportCJSNamed_Class\";
|
|||
import {ClassFoo4} from \"./ExportCJSNamed_Class\";
|
||||
|
||||
var d1: ClassFoo4T = ClassFoo4;
|
||||
var d2: ClassFoo4T = new ClassFoo4;
|
||||
var d2: ClassFoo4T = new ClassFoo4();
|
||||
// Error: ClassFoo4 (inst) ~> ClassFoo4 (class)
|
||||
//////////////////////////////////////////////
|
||||
// == Import Typeof Alias (Named Export) == //
|
||||
|
|
|
@ -99,7 +99,7 @@ class X2 {
|
|||
}
|
||||
|
||||
function x(b) {
|
||||
return b ? new X1 : new X2;
|
||||
return b ? new X1() : new X2();
|
||||
}
|
||||
|
||||
function consumer1(b) {
|
||||
|
@ -126,7 +126,7 @@ class Y2 {
|
|||
}
|
||||
|
||||
function y(b) {
|
||||
return b ? new Y1 : new Y2;
|
||||
return b ? new Y1() : new Y2();
|
||||
}
|
||||
|
||||
function consumer3(b) {
|
||||
|
@ -153,7 +153,7 @@ class Z2 {
|
|||
}
|
||||
|
||||
function z(b) {
|
||||
return b ? new Z1 : new Z2;
|
||||
return b ? new Z1() : new Z2();
|
||||
}
|
||||
|
||||
function consumer5(b) {
|
||||
|
|
|
@ -44,11 +44,11 @@ function testInterfaceName(o: I) {
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
declare class C { x: number }
|
||||
|
||||
var x: string = new C.x;
|
||||
var x: string = new C().x;
|
||||
|
||||
interface I { x: number }
|
||||
|
||||
var i = new I;
|
||||
var i = new I();
|
||||
// error
|
||||
function testInterfaceName(o: I) {
|
||||
(o.name: string);
|
||||
|
@ -177,5 +177,5 @@ interface I { foo(x: number): void }
|
|||
// error, property \`foo\` not found function
|
||||
declare class C { bar(i: I): void, bar(f: (x: number) => void): void }
|
||||
|
||||
new C.bar((x: string) => {}); // error, number ~/~> string"
|
||||
new C().bar((x: string) => {}); // error, number ~/~> string"
|
||||
`;
|
||||
|
|
|
@ -93,7 +93,7 @@ function foo(strs: Iterable<string>): void {
|
|||
}
|
||||
}
|
||||
|
||||
var m: Map<string, number> = new Map;
|
||||
var m: Map<string, number> = new Map();
|
||||
|
||||
foo(m.keys());"
|
||||
`;
|
||||
|
|
|
@ -68,13 +68,13 @@ class C {
|
|||
}
|
||||
|
||||
// check
|
||||
(new C.foo(): boolean);
|
||||
(new C().foo(): boolean);
|
||||
// last wins
|
||||
(new C.x: boolean);
|
||||
(new C().x: boolean);
|
||||
// last wins
|
||||
(new C.bar: boolean);
|
||||
(new C().bar: boolean);
|
||||
// last wins
|
||||
(new C.qux: boolean);
|
||||
(new C().qux: boolean);
|
||||
// weird outlier where last doesn\'t win in classes
|
||||
// Objects
|
||||
const o = {
|
||||
|
|
|
@ -13,10 +13,10 @@ if (undefined) {
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
var x: string = NaN;
|
||||
var y: string = Number.MAX_VALUE;
|
||||
var z: number = new TypeError.name;
|
||||
var z: number = new TypeError().name;
|
||||
var w: string = parseInt(\"...\");
|
||||
|
||||
var a = new Map;
|
||||
var a = new Map();
|
||||
a.delete(\"foobar\");
|
||||
|
||||
var b = undefined;
|
||||
|
|
|
@ -43,11 +43,11 @@ class C {
|
|||
}
|
||||
}
|
||||
C.x;
|
||||
new C.foo.x;
|
||||
new C().foo.x;
|
||||
C.bar.x;
|
||||
|
||||
import {Foo} from \"./exports_optional_prop\";
|
||||
const foo = new Foo;
|
||||
const foo = new Foo();
|
||||
(foo.bar(): string);
|
||||
// error, could be undefined
|
||||
function f(x) {
|
||||
|
|
|
@ -86,7 +86,7 @@ var B = require(\"B\");
|
|||
var f = require(\"A\").fn;
|
||||
|
||||
function C() {
|
||||
var o = new B;
|
||||
var o = new B();
|
||||
f(o.b);
|
||||
f(o.s);
|
||||
o.fn();
|
||||
|
|
|
@ -42,9 +42,9 @@ function Foo() {
|
|||
}
|
||||
Foo.prototype.m = function() {};
|
||||
|
||||
var o1: { x: number, m(): void } = new Foo;
|
||||
var o1: { x: number, m(): void } = new Foo();
|
||||
|
||||
var o2: Foo = new Foo;"
|
||||
var o2: Foo = new Foo();"
|
||||
`;
|
||||
|
||||
exports[`test super.js 1`] = `
|
||||
|
@ -58,5 +58,5 @@ class C {
|
|||
}
|
||||
class D extends C {}
|
||||
|
||||
var d: { +m: () => void } = new D;"
|
||||
var d: { +m: () => void } = new D();"
|
||||
`;
|
||||
|
|
|
@ -33,7 +33,7 @@ class Bar {
|
|||
}
|
||||
|
||||
bar(z: string, u: string): string {
|
||||
new Qux.w = \"?\";
|
||||
new Qux().w = \"?\";
|
||||
return z;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ f(x);
|
|||
|
||||
class A {}
|
||||
function h() {
|
||||
return 42 || new A;
|
||||
return 42 || new A();
|
||||
}
|
||||
|
||||
var y = h();
|
||||
|
@ -90,7 +90,7 @@ class C {
|
|||
|
||||
function foo() {
|
||||
var c = \"...\";
|
||||
c = new C;
|
||||
c = new C();
|
||||
if (bar()) {
|
||||
c.qux();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ var test1 = A.bar;
|
|||
var test2: string = A.name;
|
||||
var test3: number = A.name;
|
||||
// Error string ~> number
|
||||
var a = new A;
|
||||
var a = new A();
|
||||
var test4 = a.constructor.bar;
|
||||
// Error bar doesn\'t exist
|
||||
var test5: string = a.constructor.name;
|
||||
|
|
|
@ -61,8 +61,8 @@ class MyWriteStream extends stream.Writable {}
|
|||
class MyDuplex extends stream.Duplex {}
|
||||
class MyTransform extends stream.Duplex {}
|
||||
|
||||
new MyReadStream
|
||||
.pipe(new MyDuplex)
|
||||
.pipe(new MyTransform)
|
||||
.pipe(new MyWriteStream);"
|
||||
new MyReadStream()
|
||||
.pipe(new MyDuplex())
|
||||
.pipe(new MyTransform())
|
||||
.pipe(new MyWriteStream());"
|
||||
`;
|
||||
|
|
|
@ -96,7 +96,7 @@ class C {
|
|||
(Object.create(C.prototype): C);
|
||||
|
||||
// OK, \`instanceof C\` would be true
|
||||
(Object.create(new C): C);
|
||||
(Object.create(new C()): C);
|
||||
|
||||
// error, object literals don\'t structurally match instances
|
||||
({ foo: \"foo\" }: C);
|
||||
|
@ -127,7 +127,7 @@ class Bar extends Foo {}
|
|||
|
||||
let tests = [
|
||||
function() {
|
||||
const x = new Bar;
|
||||
const x = new Bar();
|
||||
(Object.getPrototypeOf(x): Foo);
|
||||
}
|
||||
];"
|
||||
|
@ -191,14 +191,14 @@ class Foo {
|
|||
foo() {}
|
||||
}
|
||||
// constructor and foo not enumerable
|
||||
(Object.keys(new Foo): Array<\"error\">);
|
||||
(Object.keys(new Foo()): Array<\"error\">);
|
||||
// error: prop ~> error
|
||||
class Bar extends Foo {
|
||||
bar_prop: string;
|
||||
bar() {}
|
||||
}
|
||||
// only own enumerable props
|
||||
(Object.keys(new Bar): Array<\"error\">); // error: bar_prop ~> error"
|
||||
(Object.keys(new Bar()): Array<\"error\">); // error: bar_prop ~> error"
|
||||
`;
|
||||
|
||||
exports[`test object_missing.js 1`] = `
|
||||
|
@ -403,8 +403,8 @@ var c = {
|
|||
}
|
||||
};
|
||||
var d: { [key: string]: string } = { foo: \"bar\" };
|
||||
var x = new Date;
|
||||
var y = new Foo;
|
||||
var x = new Date();
|
||||
var y = new Foo();
|
||||
|
||||
//
|
||||
// toString
|
||||
|
|
|
@ -273,7 +273,7 @@ var i:I<number> = new I();
|
|||
var j:I<number> = i.map(id => id);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
declare class I<V> { map<M>(mapper: (value?: V) => M): I<M> }
|
||||
var i: I<number> = new I;
|
||||
var i: I<number> = new I();
|
||||
var j: I<number> = i.map(id => id);"
|
||||
`;
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ declare class C {
|
|||
bar(x: { a: string }): string
|
||||
}
|
||||
|
||||
var a = new C;
|
||||
var a = new C();
|
||||
|
||||
a.foo(0);
|
||||
// ok
|
||||
|
@ -113,8 +113,8 @@ exports[`test test.js 1`] = `
|
|||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function foo() {
|
||||
var output = new FakeUint8Array;
|
||||
output.set(new FakeUint8Array, 0); // matches one of the overloads of set
|
||||
var output = new FakeUint8Array();
|
||||
output.set(new FakeUint8Array(), 0); // matches one of the overloads of set
|
||||
}"
|
||||
`;
|
||||
|
||||
|
@ -128,7 +128,7 @@ var foo = new Foo;
|
|||
(foo.bar(\'hmmm\'): number); // error
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
declare class Foo { bar(x: \"hmm\"): number, bar(x: string): string }
|
||||
var foo = new Foo;
|
||||
var foo = new Foo();
|
||||
(foo.bar(\"hmm\"): number);
|
||||
// OK
|
||||
(foo.bar(\"hmmm\"): number); // error"
|
||||
|
|
|
@ -104,7 +104,7 @@ C.prototype.foo = function() {
|
|||
return this.x;
|
||||
};
|
||||
|
||||
var c = new C;
|
||||
var c = new C();
|
||||
var x: string = c.foo();
|
||||
|
||||
function foo() {
|
||||
|
|
|
@ -12,18 +12,18 @@ function bar(): A<*> { // error, * can\'t be {} and {x: string} at the same time
|
|||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class A<X> {}
|
||||
new A;
|
||||
new A();
|
||||
// OK, implicitly inferred type args
|
||||
class B extends A {}
|
||||
// OK, same as above
|
||||
function foo(b): A<any> {
|
||||
// ok but unsafe, caller may assume any type arg
|
||||
return b ? (new A: A<number>) : (new A: A<string>);
|
||||
return b ? (new A(): A<number>) : (new A(): A<string>);
|
||||
}
|
||||
|
||||
function bar(): A<*> {
|
||||
// error, * can\'t be {} and {x: string} at the same time
|
||||
return (new A: A<{}>) || (new A: A<{ x: string }>);
|
||||
return (new A(): A<{}>) || (new A(): A<{ x: string }>);
|
||||
}"
|
||||
`;
|
||||
|
||||
|
@ -63,13 +63,13 @@ class C<T: Middle> {
|
|||
|
||||
// T is implicitly (bounded by) Middle in constructor call if not provided.
|
||||
// Explicit type arg is required in annotation - here a wildcard captures it.
|
||||
var a: C<*> = new C;
|
||||
var a: C<*> = new C();
|
||||
|
||||
a.meth(new Middle);
|
||||
a.meth(new Child);
|
||||
a.meth(new Middle());
|
||||
a.meth(new Child());
|
||||
a.meth(42);
|
||||
// Error: number ~> Middle
|
||||
a.meth(new Base); // Error: Base ~> Middle"
|
||||
a.meth(new Base()); // Error: Base ~> Middle"
|
||||
`;
|
||||
|
||||
exports[`test issue-1029.js 1`] = `
|
||||
|
|
|
@ -39,7 +39,7 @@ class B extends A<string> {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = new B;"
|
||||
module.exports = new B();"
|
||||
`;
|
||||
|
||||
exports[`test C.js 1`] = `
|
||||
|
|
|
@ -110,8 +110,8 @@ var b: number = new react.Component(); // Error: ReactComponent ~> number
|
|||
import react from \"react\";
|
||||
import {Component} from \"react\";
|
||||
|
||||
var a: Component<*, *, *> = new react.Component;
|
||||
var b: number = new react.Component; // Error: ReactComponent ~> number"
|
||||
var a: Component<*, *, *> = new react.Component();
|
||||
var b: number = new react.Component(); // Error: ReactComponent ~> number"
|
||||
`;
|
||||
|
||||
exports[`test jsx_spread.js 1`] = `
|
||||
|
|
|
@ -93,7 +93,7 @@ class P<X> {
|
|||
// this is like Promise
|
||||
type Pstar<X> = X | Pstar<P<X>>;
|
||||
// this is like Promise*
|
||||
var p: P<number> = new P;
|
||||
var p: P<number> = new P();
|
||||
(p.x: string);
|
||||
// error
|
||||
var pstar: Pstar<number> = 0;
|
||||
|
@ -105,7 +105,7 @@ pstar = p;
|
|||
// OK
|
||||
(pstar.x: string);
|
||||
// error
|
||||
pstar = (new P: P<P<number>>);
|
||||
pstar = (new P(): P<P<number>>);
|
||||
// OK
|
||||
(pstar.x: string); // error"
|
||||
`;
|
||||
|
@ -156,7 +156,7 @@ function bar() {
|
|||
class A<X> {
|
||||
x: A<A<X>>;
|
||||
}
|
||||
var a_ = new A;
|
||||
var a_ = new A();
|
||||
function foo0() {
|
||||
a_ = a_.x; // terminate despite expanding types
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ function foo1(b: S<*>) {
|
|||
class D<X> {}
|
||||
class B<X> extends D<X> {}
|
||||
class C<X> extends B<X> {}
|
||||
((new C: C<number>): D<string>); // error: number ~/~ string"
|
||||
((new C(): C<number>): D<string>); // error: number ~/~ string"
|
||||
`;
|
||||
|
||||
exports[`test test3.js 1`] = `
|
||||
|
|
|
@ -113,7 +113,7 @@ import { C, D } from \"./b2\";
|
|||
|
||||
import {C, D} from \"./b2\";
|
||||
|
||||
(new D: C);"
|
||||
(new D(): C);"
|
||||
`;
|
||||
|
||||
exports[`test c1.js 1`] = `
|
||||
|
@ -169,7 +169,7 @@ export var x = new A;
|
|||
|
||||
export class A {}
|
||||
export class B {}
|
||||
export var x = new A;"
|
||||
export var x = new A();"
|
||||
`;
|
||||
|
||||
exports[`test d2.js 1`] = `
|
||||
|
@ -304,7 +304,7 @@ import { D } from \'./g2\';
|
|||
import {C} from \"./g1\";
|
||||
import {D} from \"./g2\";
|
||||
|
||||
(new D: C);"
|
||||
(new D(): C);"
|
||||
`;
|
||||
|
||||
exports[`test h1.js 1`] = `
|
||||
|
|
|
@ -9,5 +9,5 @@ export var x = new B;
|
|||
|
||||
export class A {}
|
||||
export class B {}
|
||||
export var x = new B;"
|
||||
export var x = new B();"
|
||||
`;
|
||||
|
|
|
@ -414,7 +414,7 @@ function foo1(x: ?Foo): string {
|
|||
}
|
||||
|
||||
function foo2(x: ?Class<Foo>): string {
|
||||
return x && new x.foo || \"\";
|
||||
return x && new x().foo || \"\";
|
||||
}"
|
||||
`;
|
||||
|
||||
|
|
|
@ -15,21 +15,21 @@ var a: A = new B(); // OK (returns new A)
|
|||
function Foo() {
|
||||
return {};
|
||||
}
|
||||
var foo: number = new Foo;
|
||||
var foo: number = new Foo();
|
||||
// error (returns object literal above)
|
||||
function Bar() {
|
||||
return 0;
|
||||
}
|
||||
var bar: number = new Bar;
|
||||
var bar: number = new Bar();
|
||||
// error (returns new object)
|
||||
function Qux() {}
|
||||
var qux: number = new Qux;
|
||||
var qux: number = new Qux();
|
||||
// error (returns new object)
|
||||
class A {}
|
||||
function B() {
|
||||
return new A;
|
||||
return new A();
|
||||
}
|
||||
var a: A = new B; // OK (returns new A)"
|
||||
var a: A = new B(); // OK (returns new A)"
|
||||
`;
|
||||
|
||||
exports[`test test2.js 1`] = `
|
||||
|
@ -51,10 +51,10 @@ declare class D {
|
|||
y: any
|
||||
}
|
||||
|
||||
var d = new D;
|
||||
var d = new D();
|
||||
d.x = \"\";
|
||||
// error, string ~/~ number (but property x is found)
|
||||
(new D: D);
|
||||
(new D(): D);
|
||||
// error, new D is an object, D not in proto chain
|
||||
module.exports = D;"
|
||||
`;
|
||||
|
|
|
@ -41,7 +41,7 @@ var export_o: { x:any; } = o; // awkward type cast
|
|||
module.exports = export_o;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function Foo() {}
|
||||
var o = new Foo;
|
||||
var o = new Foo();
|
||||
var x: number = o.x;
|
||||
|
||||
Foo.prototype.m = function() {
|
||||
|
|
|
@ -38,5 +38,5 @@ C.g = function(x) {
|
|||
return x;
|
||||
};
|
||||
|
||||
var x: string = new C.f();"
|
||||
var x: string = new C().f();"
|
||||
`;
|
||||
|
|
|
@ -64,10 +64,10 @@ interface IHasXNumber { x: number }
|
|||
|
||||
interface IHasYString { y: string }
|
||||
|
||||
var testInstance1: IHasXString = new ClassWithXString;
|
||||
var testInstance2: IHasXNumber = new ClassWithXString;
|
||||
var testInstance1: IHasXString = new ClassWithXString();
|
||||
var testInstance2: IHasXNumber = new ClassWithXString();
|
||||
// Error wrong type
|
||||
var testInstance3: IHasYString = new ClassWithXString; // Error missing prop"
|
||||
var testInstance3: IHasYString = new ClassWithXString(); // Error missing prop"
|
||||
`;
|
||||
|
||||
exports[`test obj.js 1`] = `
|
||||
|
|
|
@ -286,8 +286,8 @@ class L extends L_ {
|
|||
return x;
|
||||
}
|
||||
}
|
||||
(new L_: L_);
|
||||
(new L: L);
|
||||
(new L_(): L_);
|
||||
(new L(): L);
|
||||
|
||||
// similarly, the converse is true: if the parent\'s constructor returns an
|
||||
// object, then the child does too.
|
||||
|
@ -301,8 +301,8 @@ class M extends M_ {
|
|||
return super();
|
||||
}
|
||||
}
|
||||
(new M_: { foo: string });
|
||||
(new M: { foo: string });
|
||||
(new M_(): { foo: string });
|
||||
(new M(): { foo: string });
|
||||
|
||||
// however! super() calls the parent constructor with the subclass as its \`this\`
|
||||
// value (essentially \`super.constructor.call(this)\`).
|
||||
|
@ -317,8 +317,8 @@ class N extends N_ {
|
|||
return super();
|
||||
}
|
||||
}
|
||||
(new N_: N_);
|
||||
(new N: N);"
|
||||
(new N_(): N_);
|
||||
(new N(): N);"
|
||||
`;
|
||||
|
||||
exports[`test import.js 1`] = `
|
||||
|
|
|
@ -71,17 +71,17 @@ F.prototype.m = function() {
|
|||
|
||||
function foo(p: string) {}
|
||||
|
||||
var o1 = new F;
|
||||
var o1 = new F();
|
||||
// sets o1.x to 0
|
||||
o1.x = \"\";
|
||||
foo(o1.x);
|
||||
// ok by definite assignment
|
||||
var o2 = new F;
|
||||
var o2 = new F();
|
||||
o1.y = 0;
|
||||
o2.y = \"\";
|
||||
foo(o2.y);
|
||||
// setting o1.y to 0 has no effect on o2.y
|
||||
var o3 = new F;
|
||||
var o3 = new F();
|
||||
o3.m();
|
||||
// sets o3.y to 0
|
||||
o3.y = \"\";
|
||||
|
@ -175,14 +175,14 @@ class C {
|
|||
return this;
|
||||
} // return type is C
|
||||
}
|
||||
var c = new C;
|
||||
var c = new C();
|
||||
var f = c.foo();
|
||||
var i = f();
|
||||
// OK
|
||||
(i: C);
|
||||
// OK
|
||||
class D extends C {}
|
||||
var d = new D;
|
||||
var d = new D();
|
||||
var g = d.foo();
|
||||
var j = g();
|
||||
// OK
|
||||
|
|
|
@ -83,8 +83,8 @@ class C {
|
|||
|
||||
class D extends C {}
|
||||
|
||||
var d = new D;
|
||||
(d: C).next = new C;
|
||||
var d = new D();
|
||||
(d: C).next = new C();
|
||||
(d.next: D);
|
||||
// sneaky
|
||||
class A {
|
||||
|
@ -114,7 +114,7 @@ class Invariant {
|
|||
class Misc {
|
||||
// Set<X> has invariant X
|
||||
out_set(): Set<this> {
|
||||
return new Set.add(this);
|
||||
return new Set().add(this);
|
||||
}
|
||||
in_set(_: Set<this>) {}
|
||||
inout_set: Set<this>;
|
||||
|
@ -198,7 +198,7 @@ class ImplicitNumber extends Implicit {
|
|||
arg: number;
|
||||
}
|
||||
|
||||
(new ImplicitNumber.val: string); // error: number ~> string"
|
||||
(new ImplicitNumber().val: string); // error: number ~> string"
|
||||
`;
|
||||
|
||||
exports[`test import.js 1`] = `
|
||||
|
@ -233,27 +233,27 @@ import {A3} from \"./export\";
|
|||
|
||||
class B1 extends A1 {
|
||||
foo(): B1 {
|
||||
return new B1;
|
||||
return new B1();
|
||||
} // error
|
||||
}
|
||||
|
||||
(new B1.bar(): B1);
|
||||
(new B1().bar(): B1);
|
||||
// OK
|
||||
class B3<X> extends A3<X> {
|
||||
foo(): B3<X> {
|
||||
return new B3;
|
||||
return new B3();
|
||||
} // error
|
||||
}
|
||||
|
||||
(new B3.bar(): B3<*>);
|
||||
(new B3().bar(): B3<*>);
|
||||
// OK
|
||||
(new B3.qux(0): string);
|
||||
(new B3().qux(0): string);
|
||||
// error
|
||||
(new B3.bar(): A2<*>);
|
||||
(new B3().bar(): A2<*>);
|
||||
// OK
|
||||
((new B3.bar(): B3<string>): A2<number>);
|
||||
((new B3().bar(): B3<string>): A2<number>);
|
||||
// error
|
||||
((new B3: A2<number>).qux(0): string); // error"
|
||||
((new B3(): A2<number>).qux(0): string); // error"
|
||||
`;
|
||||
|
||||
exports[`test interface.js 1`] = `
|
||||
|
@ -294,8 +294,8 @@ class C {
|
|||
}
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
(new DoublyLinkedList.prev(): DoublyLinkedList);
|
||||
(new DoublyLinkedList.next(): DoublyLinkedList);
|
||||
(new DoublyLinkedList().prev(): DoublyLinkedList);
|
||||
(new DoublyLinkedList().next(): DoublyLinkedList);
|
||||
|
||||
var MiniImmutable = require(\"mini-immutable\");
|
||||
class C {
|
||||
|
@ -321,7 +321,7 @@ class A {
|
|||
// return of foo is not annotated to get around
|
||||
// substituting this below
|
||||
bar(): this {
|
||||
return new A.foo();
|
||||
return new A().foo();
|
||||
}
|
||||
// same as returning : A, so error
|
||||
qux(): this {
|
||||
|
@ -357,7 +357,7 @@ class A {
|
|||
// describes instances of A or subclasses of A: the
|
||||
// meaning of the \`this\` type is not changed simply by
|
||||
// switching into a static context
|
||||
return new this; // but in a static context, the value \`this\` is bound to
|
||||
return new this(); // but in a static context, the value \`this\` is bound to
|
||||
// the class, instead of instances of the class
|
||||
}
|
||||
}
|
||||
|
@ -451,7 +451,7 @@ class Base {
|
|||
return this;
|
||||
}
|
||||
qux() {
|
||||
return new Base;
|
||||
return new Base();
|
||||
}
|
||||
|
||||
bar() {
|
||||
|
@ -474,22 +474,22 @@ class Override extends Base {
|
|||
}
|
||||
// OK, too
|
||||
bar() {
|
||||
return new Override;
|
||||
return new Override();
|
||||
} // OK (cf. error below)
|
||||
}
|
||||
|
||||
class InheritOverride extends Override {}
|
||||
|
||||
(new Inherit.foo(): Base);
|
||||
(new Inherit.foo(): Inherit);
|
||||
(new Inherit().foo(): Base);
|
||||
(new Inherit().foo(): Inherit);
|
||||
// error (cf. OK below)
|
||||
((new Inherit: Base).foo(): Base);
|
||||
(new Override.foo(): Base);
|
||||
(new Override.foo(): Override);
|
||||
((new Inherit(): Base).foo(): Base);
|
||||
(new Override().foo(): Base);
|
||||
(new Override().foo(): Override);
|
||||
// OK
|
||||
((new Override: Base).foo(): Base);
|
||||
((new Override(): Base).foo(): Base);
|
||||
|
||||
(new InheritOverride.bar_caller(): InheritOverride);
|
||||
(new InheritOverride().bar_caller(): InheritOverride);
|
||||
// error
|
||||
// blame flips below
|
||||
// Examples with \`this\` types (compare with examples above)
|
||||
|
@ -498,7 +498,7 @@ class Base2 {
|
|||
return this;
|
||||
}
|
||||
qux(): Base2 {
|
||||
return new Base2;
|
||||
return new Base2();
|
||||
}
|
||||
|
||||
bar(): this {
|
||||
|
@ -524,7 +524,7 @@ class Override2 extends Base2 {
|
|||
}
|
||||
// OK, too
|
||||
bar(): Override2 {
|
||||
return new Override2;
|
||||
return new Override2();
|
||||
}
|
||||
// error (cf. OK above)
|
||||
// see exploit below
|
||||
|
@ -536,16 +536,16 @@ class Override2 extends Base2 {
|
|||
|
||||
class InheritOverride2 extends Override2 {}
|
||||
|
||||
(new Inherit2.foo(): Base2);
|
||||
(new Inherit2.foo(): Inherit2);
|
||||
(new Inherit2().foo(): Base2);
|
||||
(new Inherit2().foo(): Inherit2);
|
||||
// OK (cf. error above)
|
||||
((new Inherit2: Base2).foo(): Base2);
|
||||
(new Override2.foo(): Base2);
|
||||
(new Override2.foo(): Override2);
|
||||
((new Inherit2(): Base2).foo(): Base2);
|
||||
(new Override2().foo(): Base2);
|
||||
(new Override2().foo(): Override2);
|
||||
// OK
|
||||
((new Override2: Base2).foo(): Base2);
|
||||
((new Override2(): Base2).foo(): Base2);
|
||||
|
||||
(new InheritOverride2.bar_caller(): InheritOverride2);
|
||||
(new InheritOverride2().bar_caller(): InheritOverride2);
|
||||
// exploits error above
|
||||
(new Override2: Base2).corge(new Base2); // exploits error above"
|
||||
(new Override2(): Base2).corge(new Base2()); // exploits error above"
|
||||
`;
|
||||
|
|
|
@ -27,12 +27,12 @@ function h(x: number): string {
|
|||
*/
|
||||
|
||||
function f(): number {
|
||||
throw new Error; // OK to not return
|
||||
throw new Error(); // OK to not return
|
||||
}
|
||||
|
||||
function g(a: ?string) {
|
||||
if (a == null) {
|
||||
throw new Error;
|
||||
throw new Error();
|
||||
}
|
||||
return a * 1; // a is not null
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ function h(x: number): string {
|
|||
if (x) {
|
||||
return \"foo\";
|
||||
} else {
|
||||
throw new Error;
|
||||
throw new Error();
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
|
|
@ -35,11 +35,11 @@ declare class Baz<T> {
|
|||
x: T
|
||||
}
|
||||
|
||||
(new Foo.x: number);
|
||||
(new Foo().x: number);
|
||||
// error: Qux wins
|
||||
(new Foo.y: string);
|
||||
(new Foo().y: string);
|
||||
// error: Bar wins
|
||||
(new Foo.z: number); // error: Qux wins"
|
||||
(new Foo().z: number); // error: Qux wins"
|
||||
`;
|
||||
|
||||
exports[`test test2.js 1`] = `
|
||||
|
|
|
@ -329,7 +329,7 @@ function f(b) {
|
|||
try {
|
||||
var x: number;
|
||||
if (b) {
|
||||
throw new Error;
|
||||
throw new Error();
|
||||
}
|
||||
x = 0;
|
||||
} catch (e) {}
|
||||
|
|
|
@ -92,22 +92,22 @@ mn;
|
|||
// @flow
|
||||
|
||||
class C<X> {}
|
||||
var cn: C<number> = new C;
|
||||
var cn: C<number> = new C();
|
||||
cn;
|
||||
|
||||
function foo() {
|
||||
return C;
|
||||
}
|
||||
var D = foo();
|
||||
var dn: D<number> = new C;
|
||||
var dn: D<number> = new C();
|
||||
dn;
|
||||
|
||||
type E<X> = C<X>;
|
||||
var en: E<number> = new C;
|
||||
var en: E<number> = new C();
|
||||
en;
|
||||
|
||||
type F<X> = C<void>;
|
||||
var fn: F<number> = new C;
|
||||
var fn: F<number> = new C();
|
||||
fn;
|
||||
|
||||
type O<X> = { x: X };
|
||||
|
@ -115,7 +115,7 @@ var on: O<number> = { x: 0 };
|
|||
on;
|
||||
|
||||
type Mono = C<void>;
|
||||
var mn: Mono<number> = new C;
|
||||
var mn: Mono<number> = new C();
|
||||
// error: application of non-poly type
|
||||
mn;"
|
||||
`;
|
||||
|
|
|
@ -102,9 +102,9 @@ var n = Foo;
|
|||
var o = Baz;
|
||||
|
||||
// errors from value positions only
|
||||
var a: Foo = new Foo;
|
||||
var b: Foo = new A.Foo;
|
||||
(new A.Bar: Baz);"
|
||||
var a: Foo = new Foo();
|
||||
var b: Foo = new A.Foo();
|
||||
(new A.Bar(): Baz);"
|
||||
`;
|
||||
|
||||
exports[`test import_type.js 1`] = `
|
||||
|
@ -141,8 +141,8 @@ var n = Foo;
|
|||
var o = Baz;
|
||||
|
||||
// But using it in a type should still work
|
||||
var a: Foo = new actualA.Foo;
|
||||
(new actualA.Bar: Baz);"
|
||||
var a: Foo = new actualA.Foo();
|
||||
(new actualA.Bar(): Baz);"
|
||||
`;
|
||||
|
||||
exports[`test type_alias.js 1`] = `
|
||||
|
|
|
@ -78,7 +78,7 @@ class A<T> {
|
|||
class B<T=string> extends A<T> {}
|
||||
|
||||
var b_number: B<number> = new B(123);
|
||||
var b_void: B<void> = new B;
|
||||
var b_void: B<void> = new B();
|
||||
var b_default: B<> = new B(\"hello\");
|
||||
|
||||
var b_star: B<*> = new B(123);
|
||||
|
@ -95,7 +95,7 @@ class C<T: ?string=string> extends A<T> {}
|
|||
|
||||
var c_number: C<number> = new C(123);
|
||||
// Error number ~> ?string
|
||||
var c_void: C<void> = new C;
|
||||
var c_void: C<void> = new C();
|
||||
var c_default: C<> = new C(\"hello\");
|
||||
var c_star: C<*> = new C(\"hello\");
|
||||
|
||||
|
@ -107,7 +107,7 @@ var c_star: C<*> = new C(\"hello\");
|
|||
// Error string ~> boolean
|
||||
class D<S, T=string> extends A<T> {}
|
||||
var d_number: D<mixed, number> = new D(123);
|
||||
var d_void: D<mixed, void> = new D;
|
||||
var d_void: D<mixed, void> = new D();
|
||||
var d_default: D<mixed> = new D(\"hello\");
|
||||
var d_too_few_args: D<> = new D(\"hello\");
|
||||
// Error too few tparams
|
||||
|
@ -139,7 +139,7 @@ class I<T: ?string=*> extends A<T> {}
|
|||
|
||||
var i_number: I<number> = new I(123);
|
||||
// Error number ~> ?string
|
||||
var i_void: I<void> = new I;
|
||||
var i_void: I<void> = new I();
|
||||
var i_default: I<> = new I(\"hello\");
|
||||
var i_star: I<*> = new I(\"hello\");"
|
||||
`;
|
||||
|
|
|
@ -102,7 +102,7 @@ class MyClass1 {
|
|||
// an object produced by the MyClass1 constructor
|
||||
// function.
|
||||
//
|
||||
var a: MyClass1 = new MyClass1;
|
||||
var a: MyClass1 = new MyClass1();
|
||||
|
||||
// Following tests are errors which conflate the type
|
||||
// of the class value itself with the type of its
|
||||
|
@ -136,7 +136,7 @@ class MyClass2 {
|
|||
// to a variable whose annotated type is the type of
|
||||
// the class value (constructor function) MyClass2 itself.
|
||||
//
|
||||
var c: typeof MyClass2 = new MyClass2;
|
||||
var c: typeof MyClass2 = new MyClass2();
|
||||
|
||||
//////////////////////////////////////
|
||||
// == typeof <<non-class value>> == //
|
||||
|
|
|
@ -116,7 +116,7 @@ var foo = new Foo();
|
|||
var foostr: Foo | string = foo;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
var Foo = require(\"./issue-323-lib\");
|
||||
var foo = new Foo;
|
||||
var foo = new Foo();
|
||||
var foostr: Foo | string = foo;"
|
||||
`;
|
||||
|
||||
|
@ -145,8 +145,8 @@ class Foo {}
|
|||
|
||||
class Bar {}
|
||||
|
||||
var foostr: Foo | string = new Foo;
|
||||
var barstr: Bar | string = new Bar;
|
||||
var foostr: Foo | string = new Foo();
|
||||
var barstr: Bar | string = new Bar();
|
||||
|
||||
foostr = barstr;"
|
||||
`;
|
||||
|
@ -177,7 +177,7 @@ class Tag {
|
|||
type Node = Tag_ | string;
|
||||
class Tag_ {
|
||||
constructor() {
|
||||
var a1: Array<Node> = [ new Tag_ ];
|
||||
var a1: Array<Node> = [ new Tag_() ];
|
||||
var a2: Array<Node> = a1;
|
||||
}
|
||||
}"
|
||||
|
@ -402,19 +402,19 @@ class C {}
|
|||
class D {}
|
||||
function CD(b) {
|
||||
var E = b ? C : D;
|
||||
var c: C = new E;
|
||||
var c: C = new E();
|
||||
// error, since E could be D, and D is not a subtype of C
|
||||
function qux(e: E) {}
|
||||
// this annotation is an error: is it C, or is it D?
|
||||
function qux2(e: C | D) {}
|
||||
// OK
|
||||
qux2(new C);
|
||||
qux2(new C());
|
||||
}
|
||||
|
||||
declare class F { foo(x: number): void, foo(x: string): void }
|
||||
function corge(b) {
|
||||
var x = b ? \"\" : 0;
|
||||
new F.foo(x);
|
||||
new F().foo(x);
|
||||
}"
|
||||
`;
|
||||
|
||||
|
|
|
@ -484,7 +484,7 @@ function inst(a: A5 | A6) {}
|
|||
|
||||
class B5 {}
|
||||
class B6 {}
|
||||
inst([ new B6 ]);
|
||||
inst([ new B6() ]);
|
||||
|
||||
type A5 = B5[];
|
||||
type A6 = B6[];"
|
||||
|
@ -605,7 +605,7 @@ class C<X> {}
|
|||
|
||||
function inst(a: C<number> | C<string>) {}
|
||||
|
||||
inst((new C: A3));
|
||||
inst((new C(): A3));
|
||||
|
||||
type A3 = C<B3>;
|
||||
|
||||
|
@ -1150,10 +1150,10 @@ class D {}
|
|||
function check_inst(_: C | D) {}
|
||||
|
||||
// ok
|
||||
check_inst(new D);
|
||||
check_inst(new D());
|
||||
|
||||
// ...even when they \"flow\" in
|
||||
check_inst(id(new C));
|
||||
check_inst(id(new C()));
|
||||
|
||||
////////////////////////
|
||||
// function annotations
|
||||
|
@ -1192,7 +1192,7 @@ class P<X> {}
|
|||
function check_poly_inst(_: P<number> | P<string>) {}
|
||||
|
||||
// help!
|
||||
check_poly_inst(new P);"
|
||||
check_poly_inst(new P());"
|
||||
`;
|
||||
|
||||
exports[`test test11.js 1`] = `
|
||||
|
@ -1445,7 +1445,7 @@ function f() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
new C.m(f());"
|
||||
new C().m(f());"
|
||||
`;
|
||||
|
||||
exports[`test test19.js 1`] = `
|
||||
|
@ -1467,7 +1467,7 @@ declare class D {
|
|||
// constructor overloads
|
||||
|
||||
function m<X>() {
|
||||
return new D;
|
||||
return new D();
|
||||
}
|
||||
|
||||
declare class D { constructor(_: void): void, constructor(_: null): void }"
|
||||
|
@ -1758,7 +1758,7 @@ declare class Record {
|
|||
set(x: \"bar\", y: string): void
|
||||
}
|
||||
|
||||
new Record.set(\"foo\", \"42\");"
|
||||
new Record().set(\"foo\", \"42\");"
|
||||
`;
|
||||
|
||||
exports[`test test27.js 1`] = `
|
||||
|
@ -1957,7 +1957,7 @@ declare class ImmutableMap<K, V> {}
|
|||
declare function convert<K, V>(iter: SomeIterable<[K, V]>): ImmutableMap<K, V>;
|
||||
|
||||
function foo(): ImmutableMap<string, boolean> {
|
||||
const countersGlobalMap = new SomeMap;
|
||||
const countersGlobalMap = new SomeMap();
|
||||
countersGlobalMap.set(\"\", false);
|
||||
return convert(countersGlobalMap);
|
||||
}"
|
||||
|
|
|
@ -57,11 +57,11 @@ while (node) {
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class C {
|
||||
m() {
|
||||
return new C;
|
||||
return new C();
|
||||
}
|
||||
}
|
||||
function blah() {}
|
||||
var node: ?C = new C;
|
||||
var node: ?C = new C();
|
||||
while (node) {
|
||||
var parent = node.m();
|
||||
var cloneable: C = node;
|
||||
|
|
Loading…
Reference in New Issue