Remove +1 from newline detection (#261)

* Remove +1 from newline detection

All the changes are related to spurious `;`. Sometimes the logic is more correct, sometimes less. Since `;` are going to be removed after the first save, I don't think it matters that much.

* Handle inconsistent `end` node locations when looking for newlines
master
Christopher Chedeau 2017-01-17 19:33:55 -08:00 committed by James Long
parent bc9b1fde19
commit 789a3029f4
102 changed files with 491 additions and 36 deletions

View File

@ -119,14 +119,20 @@ util.getLast = function(arr) {
}; };
function skipNewLineForward(text, index) { function skipNewLineForward(text, index) {
if (text.charAt(index) === "\n") { // What the "end" location points to is not consistent in parsers.
return index + 1; // For some statement/expressions, it's the character immediately
// afterward. For others, it's the last character in it. We need to
// scan until we hit a newline in order to skip it.
while(index < text.length) {
if (text.charAt(index) === "\n") {
return index + 1;
}
if (text.charAt(index) === "\r" && text.charAt(index + 1) === "\n") {
return index + 2;
}
index++;
} }
if (text.charAt(index) === "\r" && text.charAt(index + 1) === "\n") { return index;
return index + 2;
}
// Note: this is incorrect, but makes the current tests pass for now.
return index + 1;
} }
function _findNewline(text, index, backwards) { function _findNewline(text, index, backwards) {

View File

@ -148,12 +148,14 @@ function foo() {
} }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let myClassInstance: MyClass = null; let myClassInstance: MyClass = null;
// forward ref ok, null ~> class error // forward ref ok, null ~> class error
function bar(): MyClass { function bar(): MyClass {
return null; // forward ref ok, null ~> class error return null; // forward ref ok, null ~> class error
} }
class MyClass {} class MyClass {}
// looked up above // looked up above
function foo() { function foo() {
let myClassInstance: MyClass = mk(); let myClassInstance: MyClass = mk();

View File

@ -139,6 +139,7 @@ function bar5(x: number, y?: ?number) {
num(null + null); num(null + null);
// === 0 // === 0
num(undefined + undefined); num(undefined + undefined);
// === NaN // === NaN
num(null + 1); num(null + 1);
// === 1 // === 1
@ -147,6 +148,7 @@ num(1 + null);
num(undefined + 1); num(undefined + 1);
// === NaN // === NaN
num(1 + undefined); num(1 + undefined);
// === NaN // === NaN
num(null + true); num(null + true);
// === 1 // === 1
@ -155,6 +157,7 @@ num(true + null);
num(undefined + true); num(undefined + true);
// === NaN // === NaN
num(true + undefined); num(true + undefined);
// === NaN // === NaN
str(\"foo\" + true); str(\"foo\" + true);
// error // error
@ -167,6 +170,7 @@ str(null + \"foo\");
str(\"foo\" + undefined); str(\"foo\" + undefined);
// error // error
str(undefined + \"foo\"); str(undefined + \"foo\");
// error // error
let tests = [ let tests = [
function(x: mixed, y: mixed) { function(x: mixed, y: mixed) {
@ -200,6 +204,7 @@ let tests = [
(x + y: string); (x + y: string);
// ok // ok
(y + x: string); (y + x: string);
// ok // ok
(x + z: empty); (x + z: empty);
// error, string ~> empty // error, string ~> empty
@ -229,6 +234,7 @@ x **= 4;
let y: string = \"123\"; let y: string = \"123\";
y **= 2; y **= 2;
// error // error
1 + 2 ** 3 + 4; 1 + 2 ** 3 + 4;
2 ** 2; 2 ** 2;
@ -348,11 +354,13 @@ let tests = [
\"foo\" < { foo: 1 }; \"foo\" < { foo: 1 };
// error // error
({ foo: 1 }) < \"foo\"; ({ foo: 1 }) < \"foo\";
// error // error
var x = (null: ?number); var x = (null: ?number);
1 < x; 1 < x;
// 2 errors: null !~> number; undefined !~> number // 2 errors: null !~> number; undefined !~> number
x < 1; x < 1;
// 2 errors: null !~> number; undefined !~> number // 2 errors: null !~> number; undefined !~> number
null < null; null < null;
// error // error

View File

@ -64,6 +64,7 @@ function foo(x: string) {
var a = [ 0 ]; var a = [ 0 ];
var b = a.map(function(x) { var b = a.map(function(x) {
foo(x); foo(x);
return \"\" + x; return \"\" + x;
}); });
@ -84,6 +85,7 @@ var k: Array<number> = h.concat(h);
var l: Array<number> = h.concat(1, 2, 3); var l: Array<number> = h.concat(1, 2, 3);
var m: Array<number | string> = h.concat(\"a\", \"b\", \"c\"); var m: Array<number | string> = h.concat(\"a\", \"b\", \"c\");
var n: Array<number> = h.concat(\"a\", \"b\", \"c\"); var n: Array<number> = h.concat(\"a\", \"b\", \"c\");
// Error // Error
function reduce_test() { function reduce_test() {
/* Adapted from the following source: /* Adapted from the following source:

View File

@ -18,6 +18,7 @@ var ident = <T>(x: T): T => x;
var add = (x: number, y: number): number => x + y; var add = (x: number, y: number): number => x + y;
var bad = (x: number): string => x; var bad = (x: number): string => x;
// Error! // Error!
var ident = <T>(x: T): T => x; var ident = <T>(x: T): T => x;
(ident(1): number); (ident(1): number);

View File

@ -352,6 +352,7 @@ function test2() {
} }
var voidoid2: () => Promise<void> = voidoid1; var voidoid2: () => Promise<void> = voidoid1;
// ok // ok
var voidoid3: () => void = voidoid1; // error, void != Promise<void> var voidoid3: () => void = voidoid1; // error, void != Promise<void>
} }

View File

@ -49,6 +49,7 @@ const [ bar ] = [ \"bar\" ];
(foo: number); (foo: number);
// error: string ~> number // error: string ~> number
(bar: number); (bar: number);
// error: string ~> number // error: string ~> number
declare var bazzes: { baz: string }[]; declare var bazzes: { baz: string }[];
for (const { baz } of bazzes) { for (const { baz } of bazzes) {
@ -412,7 +413,6 @@ function var_var() {
function function_toplevel() { function function_toplevel() {
function a() { function a() {
} }
function a() { function a() {
} }
} }
@ -421,7 +421,6 @@ function function_block() {
{ {
function a() { function a() {
} }
function a() { function a() {
} }
} }
@ -889,24 +888,29 @@ function f5() {
// phasing of AST traversal, and will be fixed. // phasing of AST traversal, and will be fixed.
// //
var x: C; var x: C;
// ok // ok
var y = new C(); var y = new C();
// error: let ref before decl from value position // error: let ref before decl from value position
class C {} class C {}
var z: C = new C(); var z: C = new C();
// ok // ok
// --- vars --- // --- vars ---
// it\'s possible to annotate a var with a non-maybe type, // it\'s possible to annotate a var with a non-maybe type,
// but leave it uninitialized until later (as long as it\'s // but leave it uninitialized until later (as long as it\'s
// initialized before use) // initialized before use)
var a: number; var a: number;
// not an error per se - only if used before init // not an error per se - only if used before init
function f(n: number) { function f(n: number) {
return n; return n;
} }
f(a); f(a);
// error: undefined ~/> number // error: undefined ~/> number
a = 10; a = 10;

View File

@ -77,9 +77,11 @@ new FormData(\"\");
new FormData(document.createElement(\"input\")); new FormData(document.createElement(\"input\"));
// incorrect // incorrect
new FormData(document.createElement(\"form\")); new FormData(document.createElement(\"form\"));
// correct // correct
// has // has
const b: boolean = a.has(\"foo\"); const b: boolean = a.has(\"foo\");
// correct // correct
// get // get
const c: ?(string | File) = a.get(\"foo\"); const c: ?(string | File) = a.get(\"foo\");
@ -91,6 +93,7 @@ const e: Blob = a.get(\"foo\");
const f: ?(string | File | Blob) = a.get(\"foo\"); const f: ?(string | File | Blob) = a.get(\"foo\");
// incorrect // incorrect
a.get(2); a.get(2);
// incorrect // incorrect
// getAll // getAll
const a1: Array<string | File> = a.getAll(\"foo\"); const a1: Array<string | File> = a.getAll(\"foo\");
@ -100,6 +103,7 @@ const a2: Array<string | File | number> = a.getAll(\"foo\");
const a3: Array<string | Blob | File> = a.getAll(\"foo\"); const a3: Array<string | Blob | File> = a.getAll(\"foo\");
// incorrect // incorrect
a.getAll(23); a.getAll(23);
// incorrect // incorrect
// set // set
a.set(\"foo\", \"bar\"); a.set(\"foo\", \"bar\");
@ -121,6 +125,7 @@ a.set(\"bar\", new Blob());
a.set(\"bar\", new Blob(), \"x\"); a.set(\"bar\", new Blob(), \"x\");
// correct // correct
a.set(\"bar\", new Blob(), 2); a.set(\"bar\", new Blob(), 2);
// incorrect // incorrect
// append // append
a.append(\"foo\", \"bar\"); a.append(\"foo\", \"bar\");
@ -144,11 +149,13 @@ a.append(\"bar\", new Blob());
a.append(\"bar\", new Blob(), \"x\"); a.append(\"bar\", new Blob(), \"x\");
// correct // correct
a.append(\"bar\", new Blob(), 2); a.append(\"bar\", new Blob(), 2);
// incorrect // incorrect
// delete // delete
a.delete(\"xx\"); a.delete(\"xx\");
// correct // correct
a.delete(3); a.delete(3);
// incorrect // incorrect
// keys // keys
for (let x: string of a.keys()) { for (let x: string of a.keys()) {
@ -156,6 +163,7 @@ for (let x: string of a.keys()) {
// correct // correct
for (let x: number of a.keys()) { for (let x: number of a.keys()) {
} }
// incorrect // incorrect
// values // values
for (let x: string | File of a.values()) { for (let x: string | File of a.values()) {
@ -163,6 +171,7 @@ for (let x: string | File of a.values()) {
// correct // correct
for (let x: string | File | Blob of a.values()) { for (let x: string | File | Blob of a.values()) {
} }
// incorrect // incorrect
// entries // entries
for (let [ x, y ]: [string, string | File] of a.entries()) { for (let [ x, y ]: [string, string | File] of a.entries()) {
@ -235,6 +244,7 @@ new MutationObserver(42);
// incorrect // incorrect
new MutationObserver((n: number) => { new MutationObserver((n: number) => {
}); });
// incorrect // incorrect
// observe // observe
const div = document.createElement(\"div\"); const div = document.createElement(\"div\");
@ -253,9 +263,11 @@ o.observe(div, {});
o.observe(div, { subtree: true }); o.observe(div, { subtree: true });
// incorrect // incorrect
o.observe(div, { attributes: true, attributeFilter: true }); o.observe(div, { attributes: true, attributeFilter: true });
// incorrect // incorrect
// takeRecords // takeRecords
o.takeRecords(); o.takeRecords();
// correct // correct
// disconnect // disconnect
o.disconnect(); // correct o.disconnect(); // correct

View File

@ -22,6 +22,7 @@ var b = a.map(function(x) {
return 0; return 0;
}); });
var c: string = b[0]; var c: string = b[0];
// error: number !~> string // error: number !~> string
var array = []; var array = [];
function f() { function f() {

View File

@ -115,6 +115,7 @@ var f: { (): mixed } = function(): string {
// return type // return type
var g: { (x: string): void } = function(x: mixed) { var g: { (x: string): void } = function(x: mixed) {
}; };
// param type // param type
// A function can be an object // A function can be an object
var y: {} = function(x: number): string { var y: {} = function(x: number): string {
@ -323,6 +324,7 @@ var f: { (): mixed } = () => \"hi\";
var g: { (x: Date): void } = x => { var g: { (x: Date): void } = x => {
x * 2; x * 2;
}; };
// param type (date < number) // param type (date < number)
// A function can be an object // A function can be an object
var y: {} = x => \"hi\"; var y: {} = x => \"hi\";

View File

@ -50,12 +50,14 @@ foo(Boolean);
var dict: { [k: string]: any } = {}; var dict: { [k: string]: any } = {};
dict(); dict();
// error, callable signature not found // error, callable signature not found
interface ICall { (x: string): void } interface ICall { (x: string): void }
declare var icall: ICall; declare var icall: ICall;
icall(0); icall(0);
// error, number ~> string // error, number ~> string
icall.call(null, 0); icall.call(null, 0);
// error, number ~> string // error, number ~> string
type Callable = { (x: string): void }; type Callable = { (x: string): void };

View File

@ -71,6 +71,7 @@ class A {
} }
A.qux = function(x: string) { A.qux = function(x: string) {
}; };
// error? // error?
class B extends A { class B extends A {
static x: string; static x: string;
@ -112,6 +113,7 @@ class C<X> {
class D extends C<string> { class D extends C<string> {
static main() { static main() {
D.foo(0); D.foo(0);
// error? // error?
D.bar(0); D.bar(0);
} }

View File

@ -30,6 +30,7 @@ class B extends A {}
let b = new B(); let b = new B();
(b.foo: number); (b.foo: number);
// error, number !~> function // error, number !~> function
module.exports = B; module.exports = B;
" "
@ -56,6 +57,7 @@ class C extends B {
let c = new C(); let c = new C();
(c.foo: number); (c.foo: number);
// error, number !~> function // error, number !~> function
module.exports = C; module.exports = C;
" "
@ -135,11 +137,13 @@ x.b;
x.c; x.c;
// ok // ok
x.d; x.d;
// error, TestClass has no d // error, TestClass has no d
var y: Foo = x; var y: Foo = x;
y.b; y.b;
// error, doesn\'t exist in TestClass // error, doesn\'t exist in TestClass
y.d; y.d;
// ok, it\'s optional // ok, it\'s optional
class Test2Superclass { class Test2Superclass {
a: number; a: number;
@ -197,14 +201,17 @@ var Bar = class Foo {
var bar1: Bar = new Bar(); var bar1: Bar = new Bar();
// OK // OK
var bar2: Bar = Bar.factory(); var bar2: Bar = Bar.factory();
// OK // OK
// NB: Don\'t write expected errors using Foo to avoid error collapse hiding an // NB: Don\'t write expected errors using Foo to avoid error collapse hiding an
// unexpected failure in the above code. // unexpected failure in the above code.
var B = class Baz {}; var B = class Baz {};
var b = new Baz(); var b = new Baz();
// error: Baz is not a runtime binding in this scope // error: Baz is not a runtime binding in this scope
var C = class Qux {}; var C = class Qux {};
var c: Qux = new C(); var c: Qux = new C();
// error: Qux is not a type in this scope // error: Qux is not a type in this scope
// OK: anon classes create no binding, but can be bound manually // OK: anon classes create no binding, but can be bound manually
var Anon = class {}; var Anon = class {};
@ -263,6 +270,7 @@ C.p = \"hi\";
(C: { p: string }); (C: { p: string });
// ok // ok
(C: { p: number }); (C: { p: number });
// errors, string ~> number & vice versa (unify) // errors, string ~> number & vice versa (unify)
declare var o: { p: number }; declare var o: { p: number };
(o: Class<C>); // error, object type incompatible with class type (o: Class<C>); // error, object type incompatible with class type

View File

@ -100,11 +100,14 @@ function global_g() {
global_f(); global_f();
takes_string(global_x); takes_string(global_x);
// ok // ok
global_g(); global_g();
takes_string(global_x); takes_string(global_x);
// error // error
global_x = 42; global_x = 42;
// shouldn\'t pollute linear refinement // shouldn\'t pollute linear refinement
// local write from function // local write from function
// //
@ -119,9 +122,11 @@ function local_func() {
local_f(); local_f();
takes_string(local_x); takes_string(local_x);
// ok // ok
local_g(); local_g();
takes_string(local_x); takes_string(local_x);
// error // error
local_x = 42; // shouldn\'t pollute linear refinement local_x = 42; // shouldn\'t pollute linear refinement
} }
@ -140,11 +145,14 @@ var global_o = {
global_o.f(); global_o.f();
takes_string(global_y); takes_string(global_y);
// ok // ok
global_o.g(); global_o.g();
takes_string(global_y); takes_string(global_y);
// error // error
global_y = 42; global_y = 42;
// shouldn\'t pollute linear refinement // shouldn\'t pollute linear refinement
// local write from method // local write from method
// //
@ -161,9 +169,11 @@ function local_meth() {
local_o.f(); local_o.f();
takes_string(local_y); takes_string(local_y);
// ok // ok
local_o.g(); local_o.g();
takes_string(local_y); takes_string(local_y);
// error // error
local_y = 42; // shouldn\'t pollute linear refinement local_y = 42; // shouldn\'t pollute linear refinement
} }

View File

@ -34,8 +34,10 @@ var ColorIdToNumber = {
}; };
(ColorIdToNumber[ColorId.RED]: \"ffffff\"); (ColorIdToNumber[ColorId.RED]: \"ffffff\");
// oops // oops
ColorIdToNumber.XXX; ColorIdToNumber.XXX;
// oops // oops
module.exports = { ColorId, ColorNumber }; module.exports = { ColorId, ColorNumber };
" "
@ -61,6 +63,7 @@ var ColorIdToNumber = {
}; };
(ColorIdToNumber[ColorId.GREEN]: \"ffffff\"); (ColorIdToNumber[ColorId.GREEN]: \"ffffff\");
// oops // oops
module.exports = ColorIdToNumber; module.exports = ColorIdToNumber;
" "
@ -124,6 +127,7 @@ var obj = {
} }
}; };
var x: string = obj[\"m\"](); var x: string = obj[\"m\"]();
// error, number ~> string // error, number ~> string
var arr = [ var arr = [
function() { function() {

View File

@ -34,6 +34,7 @@ var a_2: string = m1.numVal;
import { numVal } from \"./1DoesntExist\"; import { numVal } from \"./1DoesntExist\";
var a_3: number = numVal; var a_3: number = numVal;
var a_4: string = numVal; var a_4: string = numVal;
// Error: number ~> string // Error: number ~> string
// This tests that, for node, the first name mapping that both matches *and* // This tests that, for node, the first name mapping that both matches *and*
// results in a valid module filename is picked. // results in a valid module filename is picked.
@ -44,6 +45,7 @@ var b_2: string = m2.numVal;
import { numVal as numVal2 } from \"./3DoesntExist\"; import { numVal as numVal2 } from \"./3DoesntExist\";
var b_3: number = numVal2; var b_3: number = numVal2;
var b_4: string = numVal2; var b_4: string = numVal2;
// Error: number ~> string // Error: number ~> string
// node_modules/Exists/index.js // node_modules/Exists/index.js
var m3 = require(\"4DoesntExist\"); var m3 = require(\"4DoesntExist\");

View File

@ -274,6 +274,7 @@ ws.delete(dict);
let ws2 = new WeakSet([ obj, dict ]); let ws2 = new WeakSet([ obj, dict ]);
let ws3 = new WeakSet([ 1, 2, 3 ]); let ws3 = new WeakSet([ 1, 2, 3 ]);
// error, must be objects // error, must be objects
function* generator(): Iterable<{ foo: string }> { function* generator(): Iterable<{ foo: string }> {
while (true) { while (true) {

View File

@ -53,6 +53,7 @@ type CovArrayVerbose<X, Y: X> = Array<Y>;
var b: CovArrayVerbose<number, *> = []; var b: CovArrayVerbose<number, *> = [];
var y: CovArrayVerbose<mixed, *> = b; var y: CovArrayVerbose<mixed, *> = b;
y[0] = \"\"; y[0] = \"\";
// error // error
class NVerbose<E, I: E> { class NVerbose<E, I: E> {
x: CovArrayVerbose<E, I>; x: CovArrayVerbose<E, I>;

View File

@ -91,9 +91,11 @@ var ExplicitDifferentName = require(\'ExplicitProvidesModuleDifferentName\');
var Implicit = require(\"ImplicitProvidesModule\"); var Implicit = require(\"ImplicitProvidesModule\");
(Implicit.fun(): boolean); (Implicit.fun(): boolean);
// Error: Either Implementation ~> boolean or Declaration ~> boolean // Error: Either Implementation ~> boolean or Declaration ~> boolean
var ExplicitSameName = require(\"ExplicitProvidesModuleSameName\"); var ExplicitSameName = require(\"ExplicitProvidesModuleSameName\");
(ExplicitSameName.fun(): boolean); (ExplicitSameName.fun(): boolean);
// Error: Either Implementation ~> boolean or Declaration ~> boolean // Error: Either Implementation ~> boolean or Declaration ~> boolean
var ExplicitDifferentName = require(\"ExplicitProvidesModuleDifferentName\"); var ExplicitDifferentName = require(\"ExplicitProvidesModuleDifferentName\");
(ExplicitDifferentName.fun(): boolean); // Error: Either Implementation ~> boolean or Declaration ~> boolean (ExplicitDifferentName.fun(): boolean); // Error: Either Implementation ~> boolean or Declaration ~> boolean

View File

@ -57,39 +57,50 @@ var F = require(\'package_with_dir_main\');
// This will require ./node_modules/B.js.flow // This will require ./node_modules/B.js.flow
var B1 = require(\"B\"); var B1 = require(\"B\");
(B1.fun(): boolean); (B1.fun(): boolean);
// Error either Implementation ~> boolean or Declaration ~> boolean // Error either Implementation ~> boolean or Declaration ~> boolean
// This will require ./node_modules/B.js.flow // This will require ./node_modules/B.js.flow
var B2 = require(\"B.js\"); var B2 = require(\"B.js\");
(B2.fun(): boolean); (B2.fun(): boolean);
// Error either Implementation ~> boolean or Declaration ~> boolean // Error either Implementation ~> boolean or Declaration ~> boolean
var C = require(\"package_with_full_main\"); var C = require(\"package_with_full_main\");
(C.fun(): boolean); (C.fun(): boolean);
// Error either Implementation ~> boolean or Declaration ~> boolean // Error either Implementation ~> boolean or Declaration ~> boolean
var D = require(\"package_with_partial_main\"); var D = require(\"package_with_partial_main\");
(D.fun(): boolean); (D.fun(): boolean);
// Error either Implementation ~> boolean or Declaration ~> boolean // Error either Implementation ~> boolean or Declaration ~> boolean
var E = require(\"package_with_no_package_json\"); var E = require(\"package_with_no_package_json\");
(E.fun(): boolean); (E.fun(): boolean);
// Error either Implementation ~> boolean or Declaration ~> boolean // Error either Implementation ~> boolean or Declaration ~> boolean
var F = require(\"package_with_dir_main\"); var F = require(\"package_with_dir_main\");
(F.fun(): boolean); (F.fun(): boolean);
// Error either Implementation ~> boolean or Declaration ~> boolean // Error either Implementation ~> boolean or Declaration ~> boolean
// This will require ./node_modules/B.js.flow // This will require ./node_modules/B.js.flow
var B1 = require(\"B\"); var B1 = require(\"B\");
(B1.fun(): boolean); (B1.fun(): boolean);
// Error either Implementation ~> boolean or Declaration ~> boolean // Error either Implementation ~> boolean or Declaration ~> boolean
// This will require ./node_modules/B.js.flow // This will require ./node_modules/B.js.flow
var B2 = require(\"B.js\"); var B2 = require(\"B.js\");
(B2.fun(): boolean); (B2.fun(): boolean);
// Error either Implementation ~> boolean or Declaration ~> boolean // Error either Implementation ~> boolean or Declaration ~> boolean
var C = require(\"package_with_full_main\"); var C = require(\"package_with_full_main\");
(C.fun(): boolean); (C.fun(): boolean);
// Error either Implementation ~> boolean or Declaration ~> boolean // Error either Implementation ~> boolean or Declaration ~> boolean
var D = require(\"package_with_partial_main\"); var D = require(\"package_with_partial_main\");
(D.fun(): boolean); (D.fun(): boolean);
// Error either Implementation ~> boolean or Declaration ~> boolean // Error either Implementation ~> boolean or Declaration ~> boolean
var E = require(\"package_with_no_package_json\"); var E = require(\"package_with_no_package_json\");
(E.fun(): boolean); (E.fun(): boolean);
// Error either Implementation ~> boolean or Declaration ~> boolean // Error either Implementation ~> boolean or Declaration ~> boolean
var F = require(\"package_with_dir_main\"); var F = require(\"package_with_dir_main\");
(F.fun(): boolean); // Error either Implementation ~> boolean or Declaration ~> boolean (F.fun(): boolean); // Error either Implementation ~> boolean or Declaration ~> boolean

View File

@ -46,19 +46,24 @@ var F = require(\'package_with_dir_main\');
// This will require ./node_modules/B.js.flow // This will require ./node_modules/B.js.flow
var B1 = require(\"B\"); var B1 = require(\"B\");
(B1.fun(): string); (B1.fun(): string);
// Error number ~> string // Error number ~> string
// This will require ./node_modules/B.js.flow // This will require ./node_modules/B.js.flow
var B2 = require(\"B.js\"); var B2 = require(\"B.js\");
(B2.fun(): string); (B2.fun(): string);
// Error number ~> string // Error number ~> string
var C = require(\"package_with_full_main\"); var C = require(\"package_with_full_main\");
(C.fun(): string); (C.fun(): string);
// Error number ~> string // Error number ~> string
var D = require(\"package_with_partial_main\"); var D = require(\"package_with_partial_main\");
(D.fun(): string); (D.fun(): string);
// Error number ~> string // Error number ~> string
var E = require(\"package_with_no_package_json\"); var E = require(\"package_with_no_package_json\");
(E.fun(): string); (E.fun(): string);
// Error number ~> string // Error number ~> string
var F = require(\"package_with_dir_main\"); var F = require(\"package_with_dir_main\");
(F.fun(): string); // Error number ~> string (F.fun(): string); // Error number ~> string
@ -85,10 +90,12 @@ var CJS = require(\'./CJS.js\');
// This will require ./A.js.flow // This will require ./A.js.flow
var A1 = require(\"./A\"); var A1 = require(\"./A\");
(A1.fun(): string); (A1.fun(): string);
// Error number ~> string // Error number ~> string
// This will require ./A.js.flow // This will require ./A.js.flow
var A2 = require(\"./A.js\"); var A2 = require(\"./A.js\");
(A2.fun(): string); (A2.fun(): string);
// Error number ~> string // Error number ~> string
var CJS = require(\"./CJS.js\"); var CJS = require(\"./CJS.js\");
(CJS: string); (CJS: string);

View File

@ -204,7 +204,6 @@ declare export default class Foo { givesANum(): number; };
*/ */
declare export default class Foo { givesANum(): number } declare export default class Foo { givesANum(): number }
" "
`; `;
@ -890,36 +889,44 @@ var at4: string = numberValue9; // Error: number ~> string
import * as DefaultA from \"A\"; import * as DefaultA from \"A\";
var a1: number = DefaultA.numberValue1; var a1: number = DefaultA.numberValue1;
var a2: string = DefaultA.numberValue1; var a2: string = DefaultA.numberValue1;
// Error: number ~> string // Error: number ~> string
// File path // File path
import * as DefaultB from \"./B\"; import * as DefaultB from \"./B\";
var b1: number = DefaultB.numberValue; var b1: number = DefaultB.numberValue;
var b2: string = DefaultB.numberValue; var b2: string = DefaultB.numberValue;
// Error: number ~> string // Error: number ~> string
// C.js exists, but not as a providesModule // C.js exists, but not as a providesModule
import DefaultC from \"C\"; import DefaultC from \"C\";
// Error: No such module // Error: No such module
// @providesModule D exists, but not as a filename // @providesModule D exists, but not as a filename
import DefaultD from \"./D\"; import DefaultD from \"./D\";
// Error: No such module // Error: No such module
// ================================================ // // ================================================ //
// == CommonJS Clobbering Literal Exports -> ES6 == // // == CommonJS Clobbering Literal Exports -> ES6 == //
// ================================================ // // ================================================ //
import { doesntExist1 } from \"CommonJS_Clobbering_Lit\"; import { doesntExist1 } from \"CommonJS_Clobbering_Lit\";
// Error: Not an exported binding // Error: Not an exported binding
import { numberValue1 } from \"CommonJS_Clobbering_Lit\"; import { numberValue1 } from \"CommonJS_Clobbering_Lit\";
var c1: number = numberValue1; var c1: number = numberValue1;
var c2: string = numberValue1; var c2: string = numberValue1;
// Error: number ~> string // Error: number ~> string
import { numberValue2 as numVal1 } from \"CommonJS_Clobbering_Lit\"; import { numberValue2 as numVal1 } from \"CommonJS_Clobbering_Lit\";
var d1: number = numVal1; var d1: number = numVal1;
var d2: string = numVal1; var d2: string = numVal1;
// Error: number ~> string // Error: number ~> string
import CJS_Clobb_Lit from \"CommonJS_Clobbering_Lit\"; import CJS_Clobb_Lit from \"CommonJS_Clobbering_Lit\";
var e1: number = CJS_Clobb_Lit.numberValue3; var e1: number = CJS_Clobb_Lit.numberValue3;
var e2: string = CJS_Clobb_Lit.numberValue3; var e2: string = CJS_Clobb_Lit.numberValue3;
// Error: number ~> string // Error: number ~> string
CJS_Clobb_Lit.doesntExist; CJS_Clobb_Lit.doesntExist;
// Error: doesntExist isn\'t a property // Error: doesntExist isn\'t a property
import * as CJS_Clobb_Lit_NS from \"CommonJS_Clobbering_Lit\"; import * as CJS_Clobb_Lit_NS from \"CommonJS_Clobbering_Lit\";
var f1: number = CJS_Clobb_Lit_NS.numberValue4; var f1: number = CJS_Clobb_Lit_NS.numberValue4;
@ -929,17 +936,20 @@ CJS_Clobb_Lit_NS.default.default;
var f3: string = CJS_Clobb_Lit_NS.numberValue4; var f3: string = CJS_Clobb_Lit_NS.numberValue4;
// Error: number ~> string // Error: number ~> string
var f4: string = CJS_Clobb_Lit_NS.default.numberValue5; var f4: string = CJS_Clobb_Lit_NS.default.numberValue5;
// Error: number ~> string // Error: number ~> string
// ============================================== // // ============================================== //
// == CommonJS Clobbering Class Exports -> ES6 == // // == CommonJS Clobbering Class Exports -> ES6 == //
// ============================================== // // ============================================== //
import { doesntExist2 } from \"CommonJS_Clobbering_Class\"; import { doesntExist2 } from \"CommonJS_Clobbering_Class\";
// Error: Not an exported binding // Error: Not an exported binding
// The following import should error because class statics are not turned into // The following import should error because class statics are not turned into
// named exports for now. This avoids complexities with polymorphic static // named exports for now. This avoids complexities with polymorphic static
// members (where the polymophism is defined on the class itself rather than the // members (where the polymophism is defined on the class itself rather than the
// method). // method).
import { staticNumber1, baseProp, childProp } from \"CommonJS_Clobbering_Class\"; import { staticNumber1, baseProp, childProp } from \"CommonJS_Clobbering_Class\";
// Error // Error
import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\"; import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\";
new CJS_Clobb_Class(); new CJS_Clobb_Class();
@ -950,6 +960,7 @@ var h2: string = CJS_Clobb_Class.staticNumber2();
// Error: number ~> string // Error: number ~> string
var h3: number = new CJS_Clobb_Class().instNumber1(); var h3: number = new CJS_Clobb_Class().instNumber1();
var h4: string = new CJS_Clobb_Class().instNumber1(); var h4: string = new CJS_Clobb_Class().instNumber1();
// Error: number ~> string // Error: number ~> string
import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\"; import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\";
new CJS_Clobb_Class_NS(); new CJS_Clobb_Class_NS();
@ -958,65 +969,79 @@ var i1: number = CJS_Clobb_Class_NS.staticNumber3();
// Error: Class statics not copied to Namespace object // Error: Class statics not copied to Namespace object
var i2: number = 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(); var i3: string = new CJS_Clobb_Class_NS.default().instNumber2();
// Error: number ~> string // Error: number ~> string
// =================================== // // =================================== //
// == CommonJS Named Exports -> ES6 == // // == CommonJS Named Exports -> ES6 == //
// =================================== // // =================================== //
import { doesntExist3 } from \"CommonJS_Named\"; import { doesntExist3 } from \"CommonJS_Named\";
// Error: Not an exported binding // Error: Not an exported binding
import { numberValue2 } from \"CommonJS_Named\"; import { numberValue2 } from \"CommonJS_Named\";
var j1: number = numberValue2; var j1: number = numberValue2;
var j2: string = numberValue2; var j2: string = numberValue2;
// Error: number ~> string // Error: number ~> string
import { numberValue3 as numVal3 } from \"CommonJS_Named\"; import { numberValue3 as numVal3 } from \"CommonJS_Named\";
var k1: number = numVal3; var k1: number = numVal3;
var k2: string = numVal3; var k2: string = numVal3;
// Error: number ~> string // Error: number ~> string
import * as CJS_Named from \"CommonJS_Named\"; import * as CJS_Named from \"CommonJS_Named\";
var l1: number = CJS_Named.numberValue1; var l1: number = CJS_Named.numberValue1;
var l2: string = CJS_Named.numberValue1; var l2: string = CJS_Named.numberValue1;
// Error: number ~> string // Error: number ~> string
CJS_Named.doesntExist; CJS_Named.doesntExist;
// Error: doesntExist isn\'t a property // Error: doesntExist isn\'t a property
import * as CJS_Named_NS from \"CommonJS_Named\"; import * as CJS_Named_NS from \"CommonJS_Named\";
var m1: number = CJS_Named_NS.numberValue4; var m1: number = CJS_Named_NS.numberValue4;
var m2: string = CJS_Named_NS.default.numberValue4; var m2: string = CJS_Named_NS.default.numberValue4;
// Error: CommonJS_Named has no default export // Error: CommonJS_Named has no default export
var m3: string = CJS_Named_NS.numberValue4; var m3: string = CJS_Named_NS.numberValue4;
// Error: number ~> string // Error: number ~> string
////////////////////////////// //////////////////////////////
// == ES6 Default -> ES6 == // // == ES6 Default -> ES6 == //
////////////////////////////// //////////////////////////////
import { doesntExist4 } from \"ES6_Default_AnonFunction1\"; import { doesntExist4 } from \"ES6_Default_AnonFunction1\";
// Error: Not an exported binding // Error: Not an exported binding
import ES6_Def_AnonFunc1 from \"ES6_Default_AnonFunction1\"; import ES6_Def_AnonFunc1 from \"ES6_Default_AnonFunction1\";
var n1: number = ES6_Def_AnonFunc1(); var n1: number = ES6_Def_AnonFunc1();
var n2: string = ES6_Def_AnonFunc1(); var n2: string = ES6_Def_AnonFunc1();
// Error: number ~> string // Error: number ~> string
import ES6_Def_NamedFunc1 from \"ES6_Default_NamedFunction1\"; import ES6_Def_NamedFunc1 from \"ES6_Default_NamedFunction1\";
var o1: number = ES6_Def_NamedFunc1(); var o1: number = ES6_Def_NamedFunc1();
var o2: string = ES6_Def_NamedFunc1(); var o2: string = ES6_Def_NamedFunc1();
// Error: number ~> string // Error: number ~> string
import ES6_Def_NamedClass1 from \"ES6_Default_NamedClass1\"; import ES6_Def_NamedClass1 from \"ES6_Default_NamedClass1\";
var q1: number = new ES6_Def_NamedClass1().givesANum(); var q1: number = new ES6_Def_NamedClass1().givesANum();
var q2: string = new ES6_Def_NamedClass1().givesANum(); var q2: string = new ES6_Def_NamedClass1().givesANum();
// Error: number ~> string // Error: number ~> string
//////////////////////////// ////////////////////////////
// == ES6 Named -> ES6 == // // == ES6 Named -> ES6 == //
//////////////////////////// ////////////////////////////
import doesntExist5 from \"ES6_Named1\"; import doesntExist5 from \"ES6_Named1\";
// Error: Not an exported binding // Error: Not an exported binding
import { specifierNumber1 as specifierNumber1_1 } from \"ES6_Named1\"; import { specifierNumber1 as specifierNumber1_1 } from \"ES6_Named1\";
var r1: number = specifierNumber1_1; var r1: number = specifierNumber1_1;
var r2: string = specifierNumber1_1; var r2: string = specifierNumber1_1;
// Error: number ~> string // Error: number ~> string
import { specifierNumber2Renamed } from \"ES6_Named1\"; import { specifierNumber2Renamed } from \"ES6_Named1\";
var s1: number = specifierNumber2Renamed; var s1: number = specifierNumber2Renamed;
var s2: string = specifierNumber2Renamed; var s2: string = specifierNumber2Renamed;
// Error: number ~> string // Error: number ~> string
import { specifierNumber3 as specifierNumber3Renamed } from \"ES6_Named1\"; import { specifierNumber3 as specifierNumber3Renamed } from \"ES6_Named1\";
var t1: number = specifierNumber3Renamed; var t1: number = specifierNumber3Renamed;
var t2: string = specifierNumber3Renamed; var t2: string = specifierNumber3Renamed;
// Error: number ~> string // Error: number ~> string
import { groupedSpecifierNumber1, groupedSpecifierNumber2 } from \"ES6_Named1\"; import { groupedSpecifierNumber1, groupedSpecifierNumber2 } from \"ES6_Named1\";
var u1: number = groupedSpecifierNumber1; var u1: number = groupedSpecifierNumber1;
@ -1024,14 +1049,17 @@ var u2: number = groupedSpecifierNumber2;
var u3: string = groupedSpecifierNumber1; var u3: string = groupedSpecifierNumber1;
// Error: number ~> string // Error: number ~> string
var u4: string = groupedSpecifierNumber2; var u4: string = groupedSpecifierNumber2;
// Error: number ~> string // Error: number ~> string
import { givesANumber } from \"ES6_Named1\"; import { givesANumber } from \"ES6_Named1\";
var v1: number = givesANumber(); var v1: number = givesANumber();
var v2: string = givesANumber(); var v2: string = givesANumber();
// Error: number ~> string // Error: number ~> string
import { NumberGenerator } from \"ES6_Named1\"; import { NumberGenerator } from \"ES6_Named1\";
var w1: number = new NumberGenerator().givesANumber(); var w1: number = new NumberGenerator().givesANumber();
var w2: string = new NumberGenerator().givesANumber(); var w2: string = new NumberGenerator().givesANumber();
// Error: number ~> string // Error: number ~> string
import { varDeclNumber1, varDeclNumber2 } from \"ES6_Named1\"; import { varDeclNumber1, varDeclNumber2 } from \"ES6_Named1\";
var x1: number = varDeclNumber1; var x1: number = varDeclNumber1;
@ -1039,35 +1067,43 @@ var x2: number = varDeclNumber2;
var x3: string = varDeclNumber1; var x3: string = varDeclNumber1;
// Error: number ~> string // Error: number ~> string
var x4: string = varDeclNumber2; var x4: string = varDeclNumber2;
// Error: number ~> string // Error: number ~> string
import { numberValue1 as numberValue4 } from \"ES6_ExportFrom_Intermediary1\"; import { numberValue1 as numberValue4 } from \"ES6_ExportFrom_Intermediary1\";
var aa1: number = numberValue4; var aa1: number = numberValue4;
var aa2: string = numberValue4; var aa2: string = numberValue4;
// Error: number ~> string // Error: number ~> string
import { numberValue2_renamed } from \"ES6_ExportFrom_Intermediary1\"; import { numberValue2_renamed } from \"ES6_ExportFrom_Intermediary1\";
var ab1: number = numberValue2_renamed; var ab1: number = numberValue2_renamed;
var ab2: string = numberValue2_renamed; var ab2: string = numberValue2_renamed;
// Error: number ~> string // Error: number ~> string
import { numberValue1 as numberValue5 } from \"ES6_ExportAllFrom_Intermediary1\"; import { numberValue1 as numberValue5 } from \"ES6_ExportAllFrom_Intermediary1\";
var ac1: number = numberValue5; var ac1: number = numberValue5;
var ac2: string = numberValue5; var ac2: string = numberValue5;
// Error: number ~> string // Error: number ~> string
/////////////////////////////////// ///////////////////////////////////
// == ES6 Default -> CommonJS == // // == ES6 Default -> CommonJS == //
/////////////////////////////////// ///////////////////////////////////
require(\"ES6_Default_AnonFunction2\").doesntExist; require(\"ES6_Default_AnonFunction2\").doesntExist;
// Error: \'doesntExist\' isn\'t an export // Error: \'doesntExist\' isn\'t an export
var ES6_Def_AnonFunc2 = require(\"ES6_Default_AnonFunction2\").default; var ES6_Def_AnonFunc2 = require(\"ES6_Default_AnonFunction2\").default;
var ad1: number = ES6_Def_AnonFunc2(); var ad1: number = ES6_Def_AnonFunc2();
var ad2: string = ES6_Def_AnonFunc2(); var ad2: string = ES6_Def_AnonFunc2();
// Error: number ~> string // Error: number ~> string
var ES6_Def_NamedFunc2 = require(\"ES6_Default_NamedFunction2\").default; var ES6_Def_NamedFunc2 = require(\"ES6_Default_NamedFunction2\").default;
var ae1: number = ES6_Def_NamedFunc2(); var ae1: number = ES6_Def_NamedFunc2();
var ae2: string = ES6_Def_NamedFunc2(); var ae2: string = ES6_Def_NamedFunc2();
// Error: number ~> string // Error: number ~> string
var ES6_Def_NamedClass2 = require(\"ES6_Default_NamedClass2\").default; var ES6_Def_NamedClass2 = require(\"ES6_Default_NamedClass2\").default;
var ag1: number = new ES6_Def_NamedClass2().givesANum(); var ag1: number = new ES6_Def_NamedClass2().givesANum();
var ag2: string = new ES6_Def_NamedClass2().givesANum(); var ag2: string = new ES6_Def_NamedClass2().givesANum();
// Error: number ~> string // Error: number ~> string
///////////////////////////////// /////////////////////////////////
// == ES6 Named -> CommonJS == // // == ES6 Named -> CommonJS == //
@ -1075,10 +1111,12 @@ var ag2: string = new ES6_Def_NamedClass2().givesANum();
var specifierNumber4 = require(\"ES6_Named2\").specifierNumber4; var specifierNumber4 = require(\"ES6_Named2\").specifierNumber4;
var ah1: number = specifierNumber4; var ah1: number = specifierNumber4;
var ah2: string = specifierNumber4; var ah2: string = specifierNumber4;
// Error: number ~> string // Error: number ~> string
var specifierNumber5Renamed = require(\"ES6_Named2\").specifierNumber5Renamed; var specifierNumber5Renamed = require(\"ES6_Named2\").specifierNumber5Renamed;
var ai1: number = specifierNumber5Renamed; var ai1: number = specifierNumber5Renamed;
var ai2: string = specifierNumber5Renamed; var ai2: string = specifierNumber5Renamed;
// Error: number ~> string // Error: number ~> string
var groupedSpecifierNumber3 = require(\"ES6_Named2\").groupedSpecifierNumber3; var groupedSpecifierNumber3 = require(\"ES6_Named2\").groupedSpecifierNumber3;
var groupedSpecifierNumber4 = require(\"ES6_Named2\").groupedSpecifierNumber4; var groupedSpecifierNumber4 = require(\"ES6_Named2\").groupedSpecifierNumber4;
@ -1087,14 +1125,17 @@ var aj2: number = groupedSpecifierNumber4;
var aj3: string = groupedSpecifierNumber3; var aj3: string = groupedSpecifierNumber3;
// Error: number ~> string // Error: number ~> string
var aj4: string = groupedSpecifierNumber4; var aj4: string = groupedSpecifierNumber4;
// Error: number ~> string // Error: number ~> string
var givesANumber2 = require(\"ES6_Named2\").givesANumber2; var givesANumber2 = require(\"ES6_Named2\").givesANumber2;
var ak1: number = givesANumber2(); var ak1: number = givesANumber2();
var ak2: string = givesANumber2(); var ak2: string = givesANumber2();
// Error: number ~> string // Error: number ~> string
var NumberGenerator2 = require(\"ES6_Named2\").NumberGenerator2; var NumberGenerator2 = require(\"ES6_Named2\").NumberGenerator2;
var al1: number = new NumberGenerator2().givesANumber(); var al1: number = new NumberGenerator2().givesANumber();
var al2: string = new NumberGenerator2().givesANumber(); var al2: string = new NumberGenerator2().givesANumber();
// Error: number ~> string // Error: number ~> string
var varDeclNumber3 = require(\"ES6_Named2\").varDeclNumber3; var varDeclNumber3 = require(\"ES6_Named2\").varDeclNumber3;
var varDeclNumber4 = require(\"ES6_Named2\").varDeclNumber4; var varDeclNumber4 = require(\"ES6_Named2\").varDeclNumber4;
@ -1103,20 +1144,24 @@ var am2: number = varDeclNumber4;
var am3: string = varDeclNumber3; var am3: string = varDeclNumber3;
// Error: number ~> string // Error: number ~> string
var am4: string = varDeclNumber4; var am4: string = varDeclNumber4;
// Error: number ~> string // Error: number ~> string
var numberValue6 = require(\"ES6_ExportFrom_Intermediary2\").numberValue1; var numberValue6 = require(\"ES6_ExportFrom_Intermediary2\").numberValue1;
var ap1: number = numberValue6; var ap1: number = numberValue6;
var ap2: string = numberValue6; var ap2: string = numberValue6;
// Error: number ~> string // Error: number ~> string
var numberValue2_renamed2 = require( var numberValue2_renamed2 = require(
\"ES6_ExportFrom_Intermediary2\" \"ES6_ExportFrom_Intermediary2\"
).numberValue2_renamed2; ).numberValue2_renamed2;
var aq1: number = numberValue2_renamed2; var aq1: number = numberValue2_renamed2;
var aq2: string = numberValue2_renamed2; var aq2: string = numberValue2_renamed2;
// Error: number ~> string // Error: number ~> string
var numberValue7 = require(\"ES6_ExportAllFrom_Intermediary2\").numberValue2; var numberValue7 = require(\"ES6_ExportAllFrom_Intermediary2\").numberValue2;
var ar1: number = numberValue7; var ar1: number = numberValue7;
var ar2: string = numberValue7; var ar2: string = numberValue7;
// Error: number ~> string // Error: number ~> string
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
// == ES6 Default+Named -> ES6 import Default+Named== // // == ES6 Default+Named -> ES6 import Default+Named== //
@ -1125,9 +1170,11 @@ import defaultNum, { str as namedStr } from \"./ES6_DefaultAndNamed\";
var as1: number = defaultNum; var as1: number = defaultNum;
var as2: string = defaultNum; var as2: string = defaultNum;
// Error: number ~> string // Error: number ~> string
var as3: string = namedStr; var as3: string = namedStr;
var as4: number = namedStr; var as4: number = namedStr;
// Error: string ~> number // Error: string ~> number
//////////////////////////////////////// ////////////////////////////////////////
// == Side-effect only ES6 imports == // // == Side-effect only ES6 imports == //
@ -1140,6 +1187,7 @@ import \"./SideEffects\";
import specifierNumber1 from \"ES6_Named1\"; import specifierNumber1 from \"ES6_Named1\";
// Error: Did you mean \`import {specifierNumber1} from ...\`? // Error: Did you mean \`import {specifierNumber1} from ...\`?
import { specifierNumber } from \"ES6_Named1\"; import { specifierNumber } from \"ES6_Named1\";
// Error: Did you mean \`specifierNumber1\`? // Error: Did you mean \`specifierNumber1\`?
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
// == Multi \`export *\` should combine exports == // // == Multi \`export *\` should combine exports == //
@ -1151,6 +1199,7 @@ import {
var at1: number = numberValue8; var at1: number = numberValue8;
var at2: string = numberValue8; var at2: string = numberValue8;
// Error: number ~> string // Error: number ~> string
var at3: number = numberValue9; var at3: number = numberValue9;
var at4: string = numberValue9; // Error: number ~> string var at4: string = numberValue9; // Error: number ~> string

View File

@ -30,6 +30,7 @@ import declare_m_e_with_declare_var_e from \"declare_m_e_with_declare_var_e\";
import declare_module_exports from \"declare_module_exports\"; import declare_module_exports from \"declare_module_exports\";
(declare_module_exports: number); (declare_module_exports: number);
(declare_module_exports: string); (declare_module_exports: string);
// Error: number ~> string // Error: number ~> string
// Error: Has no named export \"str\"! // Error: Has no named export \"str\"!
import { str } from \"declare_m_e_with_other_value_declares\"; import { str } from \"declare_m_e_with_other_value_declares\";
@ -37,6 +38,7 @@ import { str } from \"declare_m_e_with_other_value_declares\";
import type { str2 } from \"declare_m_e_with_other_type_declares\"; import type { str2 } from \"declare_m_e_with_other_type_declares\";
(\"asdf\": str2); (\"asdf\": str2);
(42: str2); (42: str2);
// Error: number ~> string // Error: number ~> string
/** /**
* \`declare var exports\` is deprecated, so we have a grace period where both * \`declare var exports\` is deprecated, so we have a grace period where both
@ -45,6 +47,7 @@ import type { str2 } from \"declare_m_e_with_other_type_declares\";
import DEPRECATED__declare_var_exports from \"DEPRECATED__declare_var_exports\"; import DEPRECATED__declare_var_exports from \"DEPRECATED__declare_var_exports\";
(DEPRECATED__declare_var_exports: number); (DEPRECATED__declare_var_exports: number);
(DEPRECATED__declare_var_exports: string); (DEPRECATED__declare_var_exports: string);
// Error: number ~> string // Error: number ~> string
import declare_m_e_with_declare_var_e from \"declare_m_e_with_declare_var_e\"; import declare_m_e_with_declare_var_e from \"declare_m_e_with_declare_var_e\";
(declare_m_e_with_declare_var_e: number); (declare_m_e_with_declare_var_e: number);

View File

@ -43,9 +43,11 @@ var k1: baz = 42;
var k2: baz = \"shab\"; var k2: baz = \"shab\";
// Error: string to int // Error: string to int
var k3: toz = foo(k1); var k3: toz = foo(k1);
// works // works
import type { toz } from \"ModuleAliasFoo\"; import type { toz } from \"ModuleAliasFoo\";
var k4: toz = foo(k1); var k4: toz = foo(k1);
// works // works
////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////
// == Declared Module with exports prop (issue 880) == // // == Declared Module with exports prop (issue 880) == //
@ -56,8 +58,10 @@ import type { Foo, Bar, Id } from \"foo\";
blah(0, 0); blah(0, 0);
({ toz: 3 }: Foo); ({ toz: 3 }: Foo);
// error : {toz : number} ~> string // error : {toz : number} ~> string
(3: Bar); (3: Bar);
// error : number ~> A // error : number ~> A
(\"lol\": Id<number>); // error : string ~> number (\"lol\": Id<number>); // error : string ~> number
" "

View File

@ -61,6 +61,7 @@ class PropVariance<+Out, -In> {
+con1: Out; +con1: Out;
// ok // ok
+con2: In; +con2: In;
// error // error
inv_dict1: { [k: string]: Out }; inv_dict1: { [k: string]: Out };
// error // error

View File

@ -18,6 +18,7 @@ let [ b, ...zs ] = ys;
let c = zs[0]; let c = zs[0];
// retain tuple info // retain tuple info
let d = zs[1]; let d = zs[1];
// run off the end // run off the end
(a: void); (a: void);
// error: number ~> void // error: number ~> void
@ -26,6 +27,7 @@ let d = zs[1];
(c: void); (c: void);
// error: boolean ~> void // error: boolean ~> void
(d: void); (d: void);
// error: number|string|boolean ~> void // error: number|string|boolean ~> void
let [ ...e ] = 0; let [ ...e ] = 0;
" "
@ -44,10 +46,12 @@ var { [\"key\"]: val3, ...spread } = { key: \"val\" };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var { [\"key\"]: val1 } = { key: \"val\" }; var { [\"key\"]: val1 } = { key: \"val\" };
(val1: void); (val1: void);
// error: string ~> void // error: string ~> void
var key: string = \"key\"; var key: string = \"key\";
var { [key]: val2 } = { key: \"val\" }; var { [key]: val2 } = { key: \"val\" };
(val2: void); (val2: void);
// ok (gasp!) by existing StrT -> ElemT rule // ok (gasp!) by existing StrT -> ElemT rule
var { [\"key\"]: val3, ...spread } = { key: \"val\" }; var { [\"key\"]: val3, ...spread } = { key: \"val\" };
(spread.key: void); // error (gasp!) in general we don\'t know if a computed prop should be excluded from spread (spread.key: void); // error (gasp!) in general we don\'t know if a computed prop should be excluded from spread
@ -155,6 +159,7 @@ obj_prop_fun({});
obj_prop_fun({ p: {} }); obj_prop_fun({ p: {} });
// ok // ok
obj_prop_fun({ p: { q: null } }); obj_prop_fun({ p: { q: null } });
// ok, provides add\'l lower bound // ok, provides add\'l lower bound
function obj_prop_var(o = { p: { q: \"\" } }) { function obj_prop_var(o = { p: { q: \"\" } }) {
var { p: { q = 0 } = { q: true } } = o; var { p: { q = 0 } = { q: true } } = o;
@ -172,6 +177,7 @@ obj_prop_var({});
obj_prop_var({ p: {} }); obj_prop_var({ p: {} });
// ok // ok
obj_prop_var({ p: { q: null } }); obj_prop_var({ p: { q: null } });
// ok, provides add\'l lower bound // ok, provides add\'l lower bound
function obj_rest( function obj_rest(
{ p: { q, ...o } = { q: 0, r: 0 } } = { p: { q: 0, r: \"\" } } { p: { q, ...o } = { q: 0, r: 0 } } = { p: { q: 0, r: \"\" } }
@ -210,6 +216,7 @@ var {
p: 0 p: 0
}; };
(p: void); (p: void);
// error: string ~> void // error: string ~> void
function obj_prop_err({ x: { y } } = null) { function obj_prop_err({ x: { y } } = null) {
} }
@ -222,6 +229,7 @@ function arr_elem_err([ x ] = null) {
// error: element 0 cannot be accessed on null // error: element 0 cannot be accessed on null
function arr_rest_err([ ...a ] = null) { function arr_rest_err([ ...a ] = null) {
} }
// error: expected array instead of null // error: expected array instead of null
function gen<T>(x: T, { p = x }: { p: T }): T { function gen<T>(x: T, { p = x }: { p: T }): T {
return p; return p;
@ -231,6 +239,7 @@ function gen<T>(x: T, { p = x }: { p: T }): T {
obj_prop_fun(({}: { p?: { q?: null } })); obj_prop_fun(({}: { p?: { q?: null } }));
// ok // ok
obj_prop_var(({}: { p?: { q?: null } })); obj_prop_var(({}: { p?: { q?: null } }));
// ok // ok
// union-like upper bounds preserved through destructuring // union-like upper bounds preserved through destructuring
function obj_prop_opt({ p }: { p?: string } = { p: 0 }) { function obj_prop_opt({ p }: { p?: string } = { p: 0 }) {
@ -393,6 +402,7 @@ var bp1_err: string = baseprop1;
// Error: number ~> string // Error: number ~> string
var bp2: number = others.baseprop2; var bp2: number = others.baseprop2;
var bp2_err: string = others.baseprop2; var bp2_err: string = others.baseprop2;
// Error: number ~> string // Error: number ~> string
var cp1: number = childprop1; var cp1: number = childprop1;
var cp1_err: string = childprop1; var cp1_err: string = childprop1;
@ -480,6 +490,7 @@ function obj_pattern<X>({ prop }: { prop: X }) {
type Prop<X> = { prop: X }; type Prop<X> = { prop: X };
function obj_pattern2<X>({ prop }: Prop<X>) { function obj_pattern2<X>({ prop }: Prop<X>) {
} }
// prop: X // prop: X
function arr_pattern<X>([ elem ]: X[]) { function arr_pattern<X>([ elem ]: X[]) {
} }
@ -487,6 +498,7 @@ function arr_pattern<X>([ elem ]: X[]) {
type Elem<X> = X[]; type Elem<X> = X[];
function arr_pattern2<X>([ elem ]: Elem<X>) { function arr_pattern2<X>([ elem ]: Elem<X>) {
} }
// elem: X // elem: X
function tup_pattern<X>([ proj ]: [X]) { function tup_pattern<X>([ proj ]: [X]) {
} }
@ -494,12 +506,14 @@ function tup_pattern<X>([ proj ]: [X]) {
type Proj<X> = [X]; type Proj<X> = [X];
function tup_pattern2<X>([ proj ]: Proj<X>) { function tup_pattern2<X>([ proj ]: Proj<X>) {
} }
// proj: X // proj: X
function rest_antipattern<T>(...t: T) { function rest_antipattern<T>(...t: T) {
} }
// nonsense // nonsense
function rest_pattern<X>(...r: X[]) { function rest_pattern<X>(...r: X[]) {
} }
// r: X[] // r: X[]
function obj_rest_pattern<X>({ _, ...o }: { _: any, x: X }) { function obj_rest_pattern<X>({ _, ...o }: { _: any, x: X }) {
// o: { x: X } // o: { x: X }
@ -576,6 +590,7 @@ var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var { key: val } = { key: \"val\" }; var { key: val } = { key: \"val\" };
(val: void); (val: void);
// error: string ~> void // error: string ~> void
var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" }; var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" };
(with_dash: \"motivating example\"); // ok (with_dash: \"motivating example\"); // ok

View File

@ -475,8 +475,10 @@ function unification_dict_values_invariant(x: Array<{ [k: string]: B }>) {
let a: Array<{ [k: string]: A }> = x; let a: Array<{ [k: string]: A }> = x;
// error // error
a[0].p = new A(); a[0].p = new A();
// in[0].p no longer B // in[0].p no longer B
let b: Array<{ [k: string]: B }> = x; let b: Array<{ [k: string]: B }> = x;
// ok // ok
let c: Array<{ [k: string]: C }> = x; let c: Array<{ [k: string]: C }> = x;
// error // error
@ -487,8 +489,10 @@ function subtype_dict_values_invariant(x: { [k: string]: B }) {
let a: { [k: string]: A } = x; let a: { [k: string]: A } = x;
// error // error
a.p = new A(); a.p = new A();
// x[0].p no longer B // x[0].p no longer B
let b: { [k: string]: B } = x; let b: { [k: string]: B } = x;
// ok // ok
let c: { [k: string]: C } = x; let c: { [k: string]: C } = x;
// error // error
@ -551,8 +555,10 @@ function unification_mix_with_declared_props_invariant_l(
let a: Array<{ [k: string]: B, p: A }> = x; let a: Array<{ [k: string]: B, p: A }> = x;
// error: A ~> B // error: A ~> B
a[0].p = new A(); a[0].p = new A();
// x[0].p no longer B // x[0].p no longer B
let b: Array<{ [k: string]: B, p: B }> = x; let b: Array<{ [k: string]: B, p: B }> = x;
// ok // ok
let c: Array<{ [k: string]: B, p: C }> = x; let c: Array<{ [k: string]: B, p: C }> = x;
// error // error
@ -567,8 +573,10 @@ function unification_mix_with_declared_props_invariant_r(
let a: Array<{ [k: string]: A }> = xa; let a: Array<{ [k: string]: A }> = xa;
// error // error
a[0].p = new A(); a[0].p = new A();
// xa[0].p no longer B // xa[0].p no longer B
let b: Array<{ [k: string]: B }> = xb; let b: Array<{ [k: string]: B }> = xb;
// ok // ok
let c: Array<{ [k: string]: C }> = xc; let c: Array<{ [k: string]: C }> = xc;
// error // error
@ -579,8 +587,10 @@ function subtype_mix_with_declared_props_invariant_l(x: { [k: string]: B }) {
let a: { [k: string]: B, p: A } = x; let a: { [k: string]: B, p: A } = x;
// error: A ~> B // error: A ~> B
a.p = new A(); a.p = new A();
// x.p no longer B // x.p no longer B
let b: { [k: string]: B, p: B } = x; let b: { [k: string]: B, p: B } = x;
// ok // ok
let c: { [k: string]: B, p: C } = x; let c: { [k: string]: B, p: C } = x;
// error // error
@ -595,8 +605,10 @@ function subtype_mix_with_declared_props_invariant_r(
let a: { [k: string]: A } = xa; let a: { [k: string]: A } = xa;
// error // error
a.p = new A(); a.p = new A();
// xa.p no longer B // xa.p no longer B
let b: { [k: string]: B } = xb; let b: { [k: string]: B } = xb;
// ok // ok
let c: { [k: string]: C } = xc; let c: { [k: string]: C } = xc;
// error // error
@ -619,8 +631,10 @@ function subtype_dict_to_obj(x: { [k: string]: B }) {
let a: { p: A } = x; let a: { p: A } = x;
// error // error
a.p = new A(); a.p = new A();
// x.p no longer B // x.p no longer B
let b: { p: B } = x; let b: { p: B } = x;
// ok // ok
let c: { p: C } = x; let c: { p: C } = x;
// error // error
@ -631,6 +645,7 @@ function subtype_obj_to_dict(x: { p: B }) {
let a: { [k: string]: A } = x; let a: { [k: string]: A } = x;
// error // error
a.p = new A(); a.p = new A();
// x.p no longer B // x.p no longer B
let b: { [k: string]: B } = x; let b: { [k: string]: B } = x;
@ -759,11 +774,13 @@ var x: { [key: string]: string } = {};
var y: { [key: string]: number } = x; var y: { [key: string]: number } = x;
// 2 errors, number !~> string & vice versa // 2 errors, number !~> string & vice versa
var z: { [key: number]: string } = x; var z: { [key: number]: string } = x;
// 2 errors, string !~> number & vice versa // 2 errors, string !~> number & vice versa
var a: { [key: string]: ?string } = {}; var a: { [key: string]: ?string } = {};
var b: { [key: string]: string } = a; var b: { [key: string]: string } = a;
// 2 errors (null & undefined) // 2 errors (null & undefined)
var c: { [key: string]: ?string } = b; var c: { [key: string]: ?string } = b;
// 2 errors, since c[\'x\'] = null updates b // 2 errors, since c[\'x\'] = null updates b
// 2 errors (number !~> string, string !~> number) // 2 errors (number !~> string, string !~> number)
function foo0( function foo0(

View File

@ -240,6 +240,7 @@ const a = new URL(\"http://flowtype.org/\");
const b = new URL(\"/docs\", a); const b = new URL(\"/docs\", a);
// correct // correct
const c = new URL(\"/docs\", \"http://flowtype.org/\"); const c = new URL(\"/docs\", \"http://flowtype.org/\");
// correct // correct
const d: URLSearchParams = c.searchParams; const d: URLSearchParams = c.searchParams;
// correct // correct

View File

@ -19,6 +19,7 @@ var s3 = tag2 \`la la la\`;
class A {} class A {}
var a = new A(); var a = new A();
var s1 = \`l\${a.x}r\`; var s1 = \`l\${a.x}r\`;
// error: no prop x in A // error: no prop x in A
function tag(strings, ...values) { function tag(strings, ...values) {
var x: number = strings[0]; var x: number = strings[0];

View File

@ -33,14 +33,12 @@ function isActive(
): boolean { ): boolean {
return ad.state === \"ACTIVE\"; return ad.state === \"ACTIVE\";
} }
isActive({ state: \"PAUSE\" }); isActive({ state: \"PAUSE\" });
var MyStates = { PAUSED: \"PAUSED\", ACTIVE: \"ACTIVE\", DELETED: \"DELETED\" }; var MyStates = { PAUSED: \"PAUSED\", ACTIVE: \"ACTIVE\", DELETED: \"DELETED\" };
function isActive2(ad: { state: $Keys<typeof MyStates> }): boolean { function isActive2(ad: { state: $Keys<typeof MyStates> }): boolean {
return ad.state === MyStates.ACTIVE; return ad.state === MyStates.ACTIVE;
} }
isActive2({ state: \"PAUSE\" }); isActive2({ state: \"PAUSE\" });
type Keys = $Keys<{ x: any, y: any }>; type Keys = $Keys<{ x: any, y: any }>;

View File

@ -21,6 +21,7 @@ null == 1;
1 == \"\"; 1 == \"\";
// error // error
\"\" == 1; \"\" == 1;
// error // error
var x = (null: ?number); var x = (null: ?number);
x == 1; x == 1;

View File

@ -164,7 +164,6 @@ export default class {
return 42; return 42;
} }
} }
" "
`; `;
@ -186,7 +185,6 @@ export default class {
return 42; return 42;
} }
} }
" "
`; `;
@ -277,7 +275,6 @@ export default class Foo {
return 42; return 42;
} }
} }
" "
`; `;
@ -536,7 +533,6 @@ export { groupedSpecifierNumber1, groupedSpecifierNumber2 };
export function givesANumber(): number { export function givesANumber(): number {
return 42; return 42;
} }
export class NumberGenerator { export class NumberGenerator {
givesANumber(): number { givesANumber(): number {
return 42; return 42;
@ -588,7 +584,6 @@ export { groupedSpecifierNumber3, groupedSpecifierNumber4 };
export function givesANumber2(): number { export function givesANumber2(): number {
return 42; return 42;
} }
export class NumberGenerator2 { export class NumberGenerator2 {
givesANumber(): number { givesANumber(): number {
return 42; return 42;
@ -997,36 +992,44 @@ import {typeAlias} from \"./ExportType\"; // Error: Cannot vanilla-import a type
import * as DefaultA from \"A\"; import * as DefaultA from \"A\";
var a1: number = DefaultA.numberValue1; var a1: number = DefaultA.numberValue1;
var a2: string = DefaultA.numberValue1; var a2: string = DefaultA.numberValue1;
// Error: number ~> string // Error: number ~> string
// File path // File path
import * as DefaultB from \"./B\"; import * as DefaultB from \"./B\";
var b1: number = DefaultB.numberValue; var b1: number = DefaultB.numberValue;
var b2: string = DefaultB.numberValue; var b2: string = DefaultB.numberValue;
// Error: number ~> string // Error: number ~> string
// C.js exists, but not as a providesModule // C.js exists, but not as a providesModule
import DefaultC from \"C\"; import DefaultC from \"C\";
// Error: No such module // Error: No such module
// @providesModule D exists, but not as a filename // @providesModule D exists, but not as a filename
import DefaultD from \"./D\"; import DefaultD from \"./D\";
// Error: No such module // Error: No such module
// ================================================ // // ================================================ //
// == CommonJS Clobbering Literal Exports -> ES6 == // // == CommonJS Clobbering Literal Exports -> ES6 == //
// ================================================ // // ================================================ //
import { doesntExist1 } from \"CommonJS_Clobbering_Lit\"; import { doesntExist1 } from \"CommonJS_Clobbering_Lit\";
// Error: Not an exported binding // Error: Not an exported binding
import { numberValue1 } from \"CommonJS_Clobbering_Lit\"; import { numberValue1 } from \"CommonJS_Clobbering_Lit\";
var c1: number = numberValue1; var c1: number = numberValue1;
var c2: string = numberValue1; var c2: string = numberValue1;
// Error: number ~> string // Error: number ~> string
import { numberValue2 as numVal1 } from \"CommonJS_Clobbering_Lit\"; import { numberValue2 as numVal1 } from \"CommonJS_Clobbering_Lit\";
var d1: number = numVal1; var d1: number = numVal1;
var d2: string = numVal1; var d2: string = numVal1;
// Error: number ~> string // Error: number ~> string
import CJS_Clobb_Lit from \"CommonJS_Clobbering_Lit\"; import CJS_Clobb_Lit from \"CommonJS_Clobbering_Lit\";
var e1: number = CJS_Clobb_Lit.numberValue3; var e1: number = CJS_Clobb_Lit.numberValue3;
var e2: string = CJS_Clobb_Lit.numberValue3; var e2: string = CJS_Clobb_Lit.numberValue3;
// Error: number ~> string // Error: number ~> string
CJS_Clobb_Lit.doesntExist; CJS_Clobb_Lit.doesntExist;
// Error: doesntExist isn\'t a property // Error: doesntExist isn\'t a property
import * as CJS_Clobb_Lit_NS from \"CommonJS_Clobbering_Lit\"; import * as CJS_Clobb_Lit_NS from \"CommonJS_Clobbering_Lit\";
var f1: number = CJS_Clobb_Lit_NS.numberValue4; var f1: number = CJS_Clobb_Lit_NS.numberValue4;
@ -1036,17 +1039,20 @@ CJS_Clobb_Lit_NS.default.default;
var f3: string = CJS_Clobb_Lit_NS.numberValue4; var f3: string = CJS_Clobb_Lit_NS.numberValue4;
// Error: number ~> string // Error: number ~> string
var f4: string = CJS_Clobb_Lit_NS.default.numberValue5; var f4: string = CJS_Clobb_Lit_NS.default.numberValue5;
// Error: number ~> string // Error: number ~> string
// ============================================== // // ============================================== //
// == CommonJS Clobbering Class Exports -> ES6 == // // == CommonJS Clobbering Class Exports -> ES6 == //
// ============================================== // // ============================================== //
import { doesntExist2 } from \"CommonJS_Clobbering_Class\"; import { doesntExist2 } from \"CommonJS_Clobbering_Class\";
// Error: Not an exported binding // Error: Not an exported binding
// The following import should error because class statics are not turned into // The following import should error because class statics are not turned into
// named exports for now. This avoids complexities with polymorphic static // named exports for now. This avoids complexities with polymorphic static
// members (where the polymophism is defined on the class itself rather than the // members (where the polymophism is defined on the class itself rather than the
// method). // method).
import { staticNumber1, baseProp, childProp } from \"CommonJS_Clobbering_Class\"; import { staticNumber1, baseProp, childProp } from \"CommonJS_Clobbering_Class\";
// Error // Error
import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\"; import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\";
new CJS_Clobb_Class(); new CJS_Clobb_Class();
@ -1057,6 +1063,7 @@ var h2: string = CJS_Clobb_Class.staticNumber2();
// Error: number ~> string // Error: number ~> string
var h3: number = new CJS_Clobb_Class().instNumber1(); var h3: number = new CJS_Clobb_Class().instNumber1();
var h4: string = new CJS_Clobb_Class().instNumber1(); var h4: string = new CJS_Clobb_Class().instNumber1();
// Error: number ~> string // Error: number ~> string
import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\"; import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\";
new CJS_Clobb_Class_NS(); new CJS_Clobb_Class_NS();
@ -1065,69 +1072,84 @@ var i1: number = CJS_Clobb_Class_NS.staticNumber3();
// Error: Class statics not copied to Namespace object // Error: Class statics not copied to Namespace object
var i2: number = 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(); var i3: string = new CJS_Clobb_Class_NS.default().instNumber2();
// Error: number ~> string // Error: number ~> string
// =================================== // // =================================== //
// == CommonJS Named Exports -> ES6 == // // == CommonJS Named Exports -> ES6 == //
// =================================== // // =================================== //
import { doesntExist3 } from \"CommonJS_Named\"; import { doesntExist3 } from \"CommonJS_Named\";
// Error: Not an exported binding // Error: Not an exported binding
import { numberValue2 } from \"CommonJS_Named\"; import { numberValue2 } from \"CommonJS_Named\";
var j1: number = numberValue2; var j1: number = numberValue2;
var j2: string = numberValue2; var j2: string = numberValue2;
// Error: number ~> string // Error: number ~> string
import { numberValue3 as numVal3 } from \"CommonJS_Named\"; import { numberValue3 as numVal3 } from \"CommonJS_Named\";
var k1: number = numVal3; var k1: number = numVal3;
var k2: string = numVal3; var k2: string = numVal3;
// Error: number ~> string // Error: number ~> string
import * as CJS_Named from \"CommonJS_Named\"; import * as CJS_Named from \"CommonJS_Named\";
var l1: number = CJS_Named.numberValue1; var l1: number = CJS_Named.numberValue1;
var l2: string = CJS_Named.numberValue1; var l2: string = CJS_Named.numberValue1;
// Error: number ~> string // Error: number ~> string
CJS_Named.doesntExist; CJS_Named.doesntExist;
// Error: doesntExist isn\'t a property // Error: doesntExist isn\'t a property
import * as CJS_Named_NS from \"CommonJS_Named\"; import * as CJS_Named_NS from \"CommonJS_Named\";
var m1: number = CJS_Named_NS.numberValue4; var m1: number = CJS_Named_NS.numberValue4;
var m2: string = CJS_Named_NS.default.numberValue4; var m2: string = CJS_Named_NS.default.numberValue4;
// Error: CommonJS_Named has no default export // Error: CommonJS_Named has no default export
var m3: string = CJS_Named_NS.numberValue4; var m3: string = CJS_Named_NS.numberValue4;
// Error: number ~> string // Error: number ~> string
////////////////////////////// //////////////////////////////
// == ES6 Default -> ES6 == // // == ES6 Default -> ES6 == //
////////////////////////////// //////////////////////////////
import { doesntExist4 } from \"ES6_Default_AnonFunction1\"; import { doesntExist4 } from \"ES6_Default_AnonFunction1\";
// Error: Not an exported binding // Error: Not an exported binding
import ES6_Def_AnonFunc1 from \"ES6_Default_AnonFunction1\"; import ES6_Def_AnonFunc1 from \"ES6_Default_AnonFunction1\";
var n1: number = ES6_Def_AnonFunc1(); var n1: number = ES6_Def_AnonFunc1();
var n2: string = ES6_Def_AnonFunc1(); var n2: string = ES6_Def_AnonFunc1();
// Error: number ~> string // Error: number ~> string
import ES6_Def_NamedFunc1 from \"ES6_Default_NamedFunction1\"; import ES6_Def_NamedFunc1 from \"ES6_Default_NamedFunction1\";
var o1: number = ES6_Def_NamedFunc1(); var o1: number = ES6_Def_NamedFunc1();
var o2: string = ES6_Def_NamedFunc1(); var o2: string = ES6_Def_NamedFunc1();
// Error: number ~> string // Error: number ~> string
import ES6_Def_AnonClass1 from \"ES6_Default_AnonClass1\"; import ES6_Def_AnonClass1 from \"ES6_Default_AnonClass1\";
var p1: number = new ES6_Def_AnonClass1().givesANum(); var p1: number = new ES6_Def_AnonClass1().givesANum();
var p2: string = new ES6_Def_AnonClass1().givesANum(); var p2: string = new ES6_Def_AnonClass1().givesANum();
// Error: number ~> string // Error: number ~> string
import ES6_Def_NamedClass1 from \"ES6_Default_NamedClass1\"; import ES6_Def_NamedClass1 from \"ES6_Default_NamedClass1\";
var q1: number = new ES6_Def_NamedClass1().givesANum(); var q1: number = new ES6_Def_NamedClass1().givesANum();
var q2: string = new ES6_Def_NamedClass1().givesANum(); var q2: string = new ES6_Def_NamedClass1().givesANum();
// Error: number ~> string // Error: number ~> string
//////////////////////////// ////////////////////////////
// == ES6 Named -> ES6 == // // == ES6 Named -> ES6 == //
//////////////////////////// ////////////////////////////
import doesntExist5 from \"ES6_Named1\"; import doesntExist5 from \"ES6_Named1\";
// Error: Not an exported binding // Error: Not an exported binding
import { specifierNumber1 as specifierNumber1_1 } from \"ES6_Named1\"; import { specifierNumber1 as specifierNumber1_1 } from \"ES6_Named1\";
var r1: number = specifierNumber1_1; var r1: number = specifierNumber1_1;
var r2: string = specifierNumber1_1; var r2: string = specifierNumber1_1;
// Error: number ~> string // Error: number ~> string
import { specifierNumber2Renamed } from \"ES6_Named1\"; import { specifierNumber2Renamed } from \"ES6_Named1\";
var s1: number = specifierNumber2Renamed; var s1: number = specifierNumber2Renamed;
var s2: string = specifierNumber2Renamed; var s2: string = specifierNumber2Renamed;
// Error: number ~> string // Error: number ~> string
import { specifierNumber3 as specifierNumber3Renamed } from \"ES6_Named1\"; import { specifierNumber3 as specifierNumber3Renamed } from \"ES6_Named1\";
var t1: number = specifierNumber3Renamed; var t1: number = specifierNumber3Renamed;
var t2: string = specifierNumber3Renamed; var t2: string = specifierNumber3Renamed;
// Error: number ~> string // Error: number ~> string
import { groupedSpecifierNumber1, groupedSpecifierNumber2 } from \"ES6_Named1\"; import { groupedSpecifierNumber1, groupedSpecifierNumber2 } from \"ES6_Named1\";
var u1: number = groupedSpecifierNumber1; var u1: number = groupedSpecifierNumber1;
@ -1135,14 +1157,17 @@ var u2: number = groupedSpecifierNumber2;
var u3: string = groupedSpecifierNumber1; var u3: string = groupedSpecifierNumber1;
// Error: number ~> string // Error: number ~> string
var u4: string = groupedSpecifierNumber2; var u4: string = groupedSpecifierNumber2;
// Error: number ~> string // Error: number ~> string
import { givesANumber } from \"ES6_Named1\"; import { givesANumber } from \"ES6_Named1\";
var v1: number = givesANumber(); var v1: number = givesANumber();
var v2: string = givesANumber(); var v2: string = givesANumber();
// Error: number ~> string // Error: number ~> string
import { NumberGenerator } from \"ES6_Named1\"; import { NumberGenerator } from \"ES6_Named1\";
var w1: number = new NumberGenerator().givesANumber(); var w1: number = new NumberGenerator().givesANumber();
var w2: string = new NumberGenerator().givesANumber(); var w2: string = new NumberGenerator().givesANumber();
// Error: number ~> string // Error: number ~> string
import { varDeclNumber1, varDeclNumber2 } from \"ES6_Named1\"; import { varDeclNumber1, varDeclNumber2 } from \"ES6_Named1\";
var x1: number = varDeclNumber1; var x1: number = varDeclNumber1;
@ -1150,47 +1175,58 @@ var x2: number = varDeclNumber2;
var x3: string = varDeclNumber1; var x3: string = varDeclNumber1;
// Error: number ~> string // Error: number ~> string
var x4: string = varDeclNumber2; var x4: string = varDeclNumber2;
// Error: number ~> string // Error: number ~> string
import { destructuredObjNumber } from \"ES6_Named1\"; import { destructuredObjNumber } from \"ES6_Named1\";
var y1: number = destructuredObjNumber; var y1: number = destructuredObjNumber;
var y2: string = destructuredObjNumber; var y2: string = destructuredObjNumber;
// Error: number ~> string // Error: number ~> string
import { destructuredArrNumber } from \"ES6_Named1\"; import { destructuredArrNumber } from \"ES6_Named1\";
var z1: number = destructuredArrNumber; var z1: number = destructuredArrNumber;
var z2: string = destructuredArrNumber; var z2: string = destructuredArrNumber;
// Error: number ~> string // Error: number ~> string
import { numberValue1 as numberValue4 } from \"ES6_ExportFrom_Intermediary1\"; import { numberValue1 as numberValue4 } from \"ES6_ExportFrom_Intermediary1\";
var aa1: number = numberValue4; var aa1: number = numberValue4;
var aa2: string = numberValue4; var aa2: string = numberValue4;
// Error: number ~> string // Error: number ~> string
import { numberValue2_renamed } from \"ES6_ExportFrom_Intermediary1\"; import { numberValue2_renamed } from \"ES6_ExportFrom_Intermediary1\";
var ab1: number = numberValue2_renamed; var ab1: number = numberValue2_renamed;
var ab2: string = numberValue2_renamed; var ab2: string = numberValue2_renamed;
// Error: number ~> string // Error: number ~> string
import { numberValue1 as numberValue5 } from \"ES6_ExportAllFrom_Intermediary1\"; import { numberValue1 as numberValue5 } from \"ES6_ExportAllFrom_Intermediary1\";
var ac1: number = numberValue5; var ac1: number = numberValue5;
var ac2: string = numberValue5; var ac2: string = numberValue5;
// Error: number ~> string // Error: number ~> string
/////////////////////////////////// ///////////////////////////////////
// == ES6 Default -> CommonJS == // // == ES6 Default -> CommonJS == //
/////////////////////////////////// ///////////////////////////////////
require(\"ES6_Default_AnonFunction2\").doesntExist; require(\"ES6_Default_AnonFunction2\").doesntExist;
// Error: \'doesntExist\' isn\'t an export // Error: \'doesntExist\' isn\'t an export
var ES6_Def_AnonFunc2 = require(\"ES6_Default_AnonFunction2\").default; var ES6_Def_AnonFunc2 = require(\"ES6_Default_AnonFunction2\").default;
var ad1: number = ES6_Def_AnonFunc2(); var ad1: number = ES6_Def_AnonFunc2();
var ad2: string = ES6_Def_AnonFunc2(); var ad2: string = ES6_Def_AnonFunc2();
// Error: number ~> string // Error: number ~> string
var ES6_Def_NamedFunc2 = require(\"ES6_Default_NamedFunction2\").default; var ES6_Def_NamedFunc2 = require(\"ES6_Default_NamedFunction2\").default;
var ae1: number = ES6_Def_NamedFunc2(); var ae1: number = ES6_Def_NamedFunc2();
var ae2: string = ES6_Def_NamedFunc2(); var ae2: string = ES6_Def_NamedFunc2();
// Error: number ~> string // Error: number ~> string
var ES6_Def_AnonClass2 = require(\"ES6_Default_AnonClass2\").default; var ES6_Def_AnonClass2 = require(\"ES6_Default_AnonClass2\").default;
var af1: number = new ES6_Def_AnonClass2().givesANum(); var af1: number = new ES6_Def_AnonClass2().givesANum();
var af2: string = new ES6_Def_AnonClass2().givesANum(); var af2: string = new ES6_Def_AnonClass2().givesANum();
// Error: number ~> string // Error: number ~> string
var ES6_Def_NamedClass2 = require(\"ES6_Default_NamedClass2\").default; var ES6_Def_NamedClass2 = require(\"ES6_Default_NamedClass2\").default;
var ag1: number = new ES6_Def_NamedClass2().givesANum(); var ag1: number = new ES6_Def_NamedClass2().givesANum();
var ag2: string = new ES6_Def_NamedClass2().givesANum(); var ag2: string = new ES6_Def_NamedClass2().givesANum();
// Error: number ~> string // Error: number ~> string
///////////////////////////////// /////////////////////////////////
// == ES6 Named -> CommonJS == // // == ES6 Named -> CommonJS == //
@ -1198,10 +1234,12 @@ var ag2: string = new ES6_Def_NamedClass2().givesANum();
var specifierNumber4 = require(\"ES6_Named2\").specifierNumber4; var specifierNumber4 = require(\"ES6_Named2\").specifierNumber4;
var ah1: number = specifierNumber4; var ah1: number = specifierNumber4;
var ah2: string = specifierNumber4; var ah2: string = specifierNumber4;
// Error: number ~> string // Error: number ~> string
var specifierNumber5Renamed = require(\"ES6_Named2\").specifierNumber5Renamed; var specifierNumber5Renamed = require(\"ES6_Named2\").specifierNumber5Renamed;
var ai1: number = specifierNumber5Renamed; var ai1: number = specifierNumber5Renamed;
var ai2: string = specifierNumber5Renamed; var ai2: string = specifierNumber5Renamed;
// Error: number ~> string // Error: number ~> string
var groupedSpecifierNumber3 = require(\"ES6_Named2\").groupedSpecifierNumber3; var groupedSpecifierNumber3 = require(\"ES6_Named2\").groupedSpecifierNumber3;
var groupedSpecifierNumber4 = require(\"ES6_Named2\").groupedSpecifierNumber4; var groupedSpecifierNumber4 = require(\"ES6_Named2\").groupedSpecifierNumber4;
@ -1210,14 +1248,17 @@ var aj2: number = groupedSpecifierNumber4;
var aj3: string = groupedSpecifierNumber3; var aj3: string = groupedSpecifierNumber3;
// Error: number ~> string // Error: number ~> string
var aj4: string = groupedSpecifierNumber4; var aj4: string = groupedSpecifierNumber4;
// Error: number ~> string // Error: number ~> string
var givesANumber2 = require(\"ES6_Named2\").givesANumber2; var givesANumber2 = require(\"ES6_Named2\").givesANumber2;
var ak1: number = givesANumber2(); var ak1: number = givesANumber2();
var ak2: string = givesANumber2(); var ak2: string = givesANumber2();
// Error: number ~> string // Error: number ~> string
var NumberGenerator2 = require(\"ES6_Named2\").NumberGenerator2; var NumberGenerator2 = require(\"ES6_Named2\").NumberGenerator2;
var al1: number = new NumberGenerator2().givesANumber(); var al1: number = new NumberGenerator2().givesANumber();
var al2: string = new NumberGenerator2().givesANumber(); var al2: string = new NumberGenerator2().givesANumber();
// Error: number ~> string // Error: number ~> string
var varDeclNumber3 = require(\"ES6_Named2\").varDeclNumber3; var varDeclNumber3 = require(\"ES6_Named2\").varDeclNumber3;
var varDeclNumber4 = require(\"ES6_Named2\").varDeclNumber4; var varDeclNumber4 = require(\"ES6_Named2\").varDeclNumber4;
@ -1226,28 +1267,34 @@ var am2: number = varDeclNumber4;
var am3: string = varDeclNumber3; var am3: string = varDeclNumber3;
// Error: number ~> string // Error: number ~> string
var am4: string = varDeclNumber4; var am4: string = varDeclNumber4;
// Error: number ~> string // Error: number ~> string
var destructuredObjNumber2 = require(\"ES6_Named2\").destructuredObjNumber2; var destructuredObjNumber2 = require(\"ES6_Named2\").destructuredObjNumber2;
var an1: number = destructuredObjNumber2; var an1: number = destructuredObjNumber2;
var an2: string = destructuredObjNumber2; var an2: string = destructuredObjNumber2;
// Error: number ~> string // Error: number ~> string
var destructuredArrNumber2 = require(\"ES6_Named2\").destructuredArrNumber2; var destructuredArrNumber2 = require(\"ES6_Named2\").destructuredArrNumber2;
var ao1: number = destructuredArrNumber2; var ao1: number = destructuredArrNumber2;
var ao2: string = destructuredArrNumber2; var ao2: string = destructuredArrNumber2;
// Error: number ~> string // Error: number ~> string
var numberValue6 = require(\"ES6_ExportFrom_Intermediary2\").numberValue1; var numberValue6 = require(\"ES6_ExportFrom_Intermediary2\").numberValue1;
var ap1: number = numberValue6; var ap1: number = numberValue6;
var ap2: string = numberValue6; var ap2: string = numberValue6;
// Error: number ~> string // Error: number ~> string
var numberValue2_renamed2 = require( var numberValue2_renamed2 = require(
\"ES6_ExportFrom_Intermediary2\" \"ES6_ExportFrom_Intermediary2\"
).numberValue2_renamed2; ).numberValue2_renamed2;
var aq1: number = numberValue2_renamed2; var aq1: number = numberValue2_renamed2;
var aq2: string = numberValue2_renamed2; var aq2: string = numberValue2_renamed2;
// Error: number ~> string // Error: number ~> string
var numberValue7 = require(\"ES6_ExportAllFrom_Intermediary2\").numberValue2; var numberValue7 = require(\"ES6_ExportAllFrom_Intermediary2\").numberValue2;
var ar1: number = numberValue7; var ar1: number = numberValue7;
var ar2: string = numberValue7; var ar2: string = numberValue7;
// Error: number ~> string // Error: number ~> string
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
// == ES6 Default+Named -> ES6 import Default+Named== // // == ES6 Default+Named -> ES6 import Default+Named== //
@ -1256,9 +1303,11 @@ import defaultNum, { str as namedStr } from \"./ES6_DefaultAndNamed\";
var as1: number = defaultNum; var as1: number = defaultNum;
var as2: string = defaultNum; var as2: string = defaultNum;
// Error: number ~> string // Error: number ~> string
var as3: string = namedStr; var as3: string = namedStr;
var as4: number = namedStr; var as4: number = namedStr;
// Error: string ~> number // Error: string ~> number
//////////////////////////////////////// ////////////////////////////////////////
// == Side-effect only ES6 imports == // // == Side-effect only ES6 imports == //
@ -1271,6 +1320,7 @@ import \"./SideEffects\";
import specifierNumber1 from \"ES6_Named1\"; import specifierNumber1 from \"ES6_Named1\";
// Error: Did you mean \`import {specifierNumber1} from ...\`? // Error: Did you mean \`import {specifierNumber1} from ...\`?
import { specifierNumber } from \"ES6_Named1\"; import { specifierNumber } from \"ES6_Named1\";
// Error: Did you mean \`specifierNumber1\`? // Error: Did you mean \`specifierNumber1\`?
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
// == Multi \`export *\` should combine exports == // // == Multi \`export *\` should combine exports == //
@ -1282,9 +1332,11 @@ import {
var at1: number = numberValue8; var at1: number = numberValue8;
var at2: string = numberValue8; var at2: string = numberValue8;
// Error: number ~> string // Error: number ~> string
var at3: number = numberValue9; var at3: number = numberValue9;
var at4: string = numberValue9; var at4: string = numberValue9;
// Error: number ~> string // Error: number ~> string
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
// == Vanilla \`import\` cannot import a type-only export == // // == Vanilla \`import\` cannot import a type-only export == //
@ -1358,28 +1410,34 @@ function testRequires() {
// CommonJS module // CommonJS module
import * as DefaultA from \"A\"; import * as DefaultA from \"A\";
DefaultA.numberValue1 = 123; DefaultA.numberValue1 = 123;
// Error: DefaultA is frozen // Error: DefaultA is frozen
// ES6 module // ES6 module
import * as ES6_Named1 from \"ES6_Named1\"; import * as ES6_Named1 from \"ES6_Named1\";
ES6_Named1.varDeclNumber1 = 123; ES6_Named1.varDeclNumber1 = 123;
// Error: ES6_Named1 is frozen // Error: ES6_Named1 is frozen
// CommonJS module that clobbers module.exports // CommonJS module that clobbers module.exports
import * as CommonJS_Star from \"CommonJS_Clobbering_Lit\"; import * as CommonJS_Star from \"CommonJS_Clobbering_Lit\";
CommonJS_Star.numberValue1 = 123; CommonJS_Star.numberValue1 = 123;
// Error: frozen // Error: frozen
CommonJS_Star.default.numberValue1 = 123; CommonJS_Star.default.numberValue1 = 123;
// ok // ok
import CommonJS_Clobbering_Lit from \"CommonJS_Clobbering_Lit\"; import CommonJS_Clobbering_Lit from \"CommonJS_Clobbering_Lit\";
CommonJS_Clobbering_Lit.numberValue1 = 123; CommonJS_Clobbering_Lit.numberValue1 = 123;
// ok // ok
// CommonJS module that clobbers module.exports with a frozen object // CommonJS module that clobbers module.exports with a frozen object
import * as CommonJS_Frozen_Star from \"CommonJS_Clobbering_Frozen\"; import * as CommonJS_Frozen_Star from \"CommonJS_Clobbering_Frozen\";
CommonJS_Frozen_Star.numberValue1 = 123; CommonJS_Frozen_Star.numberValue1 = 123;
// Error: frozen // Error: frozen
CommonJS_Frozen_Star.default.numberValue1 = 123; CommonJS_Frozen_Star.default.numberValue1 = 123;
// Error: frozen // Error: frozen
import CommonJS_Clobbering_Frozen from \"CommonJS_Clobbering_Frozen\"; import CommonJS_Clobbering_Frozen from \"CommonJS_Clobbering_Frozen\";
CommonJS_Clobbering_Frozen.numberValue1 = 123; CommonJS_Clobbering_Frozen.numberValue1 = 123;
// Error: exports are frozen // Error: exports are frozen
// //
// Requires // Requires
@ -1388,14 +1446,17 @@ function testRequires() {
// CommonJS module // CommonJS module
var DefaultA = require(\"A\"); var DefaultA = require(\"A\");
DefaultA.numberValue1 = 123; DefaultA.numberValue1 = 123;
// ok, not frozen by default // ok, not frozen by default
// ES6 module // ES6 module
var ES6_Named1 = require(\"ES6_Named1\"); var ES6_Named1 = require(\"ES6_Named1\");
ES6_Named1.numberValue = 123; ES6_Named1.numberValue = 123;
// error, es6 exports are frozen // error, es6 exports are frozen
// CommonJS module that clobbers module.exports // CommonJS module that clobbers module.exports
var CommonJS_Star = require(\"CommonJS_Clobbering_Lit\"); var CommonJS_Star = require(\"CommonJS_Clobbering_Lit\");
CommonJS_Star.numberValue1 = 123; CommonJS_Star.numberValue1 = 123;
// ok, not frozen by default // ok, not frozen by default
// CommonJS module that clobbers module.exports with a frozen object // CommonJS module that clobbers module.exports with a frozen object
var CommonJS_Frozen_Star = require(\"CommonJS_Clobbering_Frozen\"); var CommonJS_Frozen_Star = require(\"CommonJS_Clobbering_Frozen\");

View File

@ -53,6 +53,7 @@ import CJS_Named from \"CJS_Named\";
// Error: string ~> number // Error: string ~> number
(CJS_Named: { num1: number, str1: string }); (CJS_Named: { num1: number, str1: string });
(CJS_Named: number); (CJS_Named: number);
// Error: Module ~> number // Error: Module ~> number
import { num2 } from \"CJS_Clobbered\"; import { num2 } from \"CJS_Clobbered\";
// Error: No such export! // Error: No such export!
@ -63,16 +64,19 @@ import { numExport } from \"CJS_Clobbered\";
import type { numType } from \"CJS_Clobbered\"; import type { numType } from \"CJS_Clobbered\";
(42: numType); (42: numType);
(\"asdf\": numType); (\"asdf\": numType);
// Error: string ~> number // Error: string ~> number
import { strHidden } from \"ES\"; import { strHidden } from \"ES\";
// Error: No such export! // Error: No such export!
import { str3 } from \"ES\"; import { str3 } from \"ES\";
(str3: string); (str3: string);
(str3: number); (str3: number);
// Error: string ~> number // Error: string ~> number
import { num3 } from \"ES\"; import { num3 } from \"ES\";
(num3: number); (num3: number);
(num3: string); (num3: string);
// Error: number ~> string // Error: number ~> string
import { C } from \"ES\"; import { C } from \"ES\";
import type { C as CType } from \"ES\"; import type { C as CType } from \"ES\";
@ -81,12 +85,14 @@ import type { C as CType } from \"ES\";
// Error: number ~> C // Error: number ~> C
(new C(): CType); (new C(): CType);
(42: CType); (42: CType);
// Error: number ~> CType // Error: number ~> CType
import { T } from \"ES\"; import { T } from \"ES\";
// Error: T is a type import, not a value // Error: T is a type import, not a value
import type { T as T2 } from \"ES\"; import type { T as T2 } from \"ES\";
(42: T2); (42: T2);
(\"asdf\": T2); (\"asdf\": T2);
// Error: string ~> number // Error: string ~> number
import { exports as nope } from \"ES\"; // Error: Not an export import { exports as nope } from \"ES\"; // Error: Not an export
" "

View File

@ -15,6 +15,7 @@ import { source } from \"./test\";
var a: number = source.num; var a: number = source.num;
var b: string = source.num; var b: string = source.num;
// Error: num ~> string // Error: num ~> string
var c: string = source.str; var c: string = source.str;
var d: number = source.str; // Error: num ~> string var d: number = source.str; // Error: num ~> string

View File

@ -15,6 +15,7 @@ import { source } from \"./test\";
var a: number = source.num; var a: number = source.num;
var b: string = source.num; var b: string = source.num;
// Error: num ~> string // Error: num ~> string
var c: string = source.str; var c: string = source.str;
var d: number = source.str; // Ignored error: num ~> string var d: number = source.str; // Ignored error: num ~> string

View File

@ -60,24 +60,30 @@ import type {
var a: inlinedType1 = 42; var a: inlinedType1 = 42;
var b: inlinedType1 = \"asdf\"; var b: inlinedType1 = \"asdf\";
// Error: string ~> number // Error: string ~> number
var c: standaloneType1 = 42; var c: standaloneType1 = 42;
var d: standaloneType1 = \"asdf\"; var d: standaloneType1 = \"asdf\";
// Error: string ~> number // Error: string ~> number
var e: talias1 = 42; var e: talias1 = 42;
var f: talias1 = \"asdf\"; var f: talias1 = \"asdf\";
// Error: string ~> number // Error: string ~> number
var g: talias3 = 42; var g: talias3 = 42;
var h: talias3 = \"asdf\"; var h: talias3 = \"asdf\";
// Error: string ~> number // Error: string ~> number
import type { talias4 } from \"./cjs_with_types\"; import type { talias4 } from \"./cjs_with_types\";
var i: talias4 = 42; var i: talias4 = 42;
var j: talias4 = \"asdf\"; var j: talias4 = \"asdf\";
// Error: string ~> number // Error: string ~> number
import { IFoo, IFoo2 } from \"./types_only\"; import { IFoo, IFoo2 } from \"./types_only\";
var k: IFoo = { prop: 42 }; var k: IFoo = { prop: 42 };
var l: IFoo = { prop: \"asdf\" }; var l: IFoo = { prop: \"asdf\" };
// Error: {prop:string} ~> {prop:number} // Error: {prop:string} ~> {prop:number}
var m: IFoo2 = { prop: \"asdf\" }; var m: IFoo2 = { prop: \"asdf\" };
var n: IFoo2 = { prop: 42 }; // Error: {prop:number} ~> {prop:string} var n: IFoo2 = { prop: 42 }; // Error: {prop:number} ~> {prop:string}
@ -106,17 +112,18 @@ export interface IFoo { prop: number };
export type inlinedType1 = number; export type inlinedType1 = number;
var a: inlinedType1 = 42; var a: inlinedType1 = 42;
var b: inlinedType1 = \"asdf\"; var b: inlinedType1 = \"asdf\";
// Error: string ~> number // Error: string ~> number
type standaloneType1 = number; type standaloneType1 = number;
export type { standaloneType1 }; export type { standaloneType1 };
type standaloneType2 = number; type standaloneType2 = number;
export { standaloneType2 }; export { standaloneType2 };
// Error: Missing \`type\` keyword // Error: Missing \`type\` keyword
export type { talias1, talias2 as talias3, IFoo2 } from \"./types_only2\"; export type { talias1, talias2 as talias3, IFoo2 } from \"./types_only2\";
export interface IFoo { prop: number } export interface IFoo { prop: number }
" "
`; `;
@ -132,6 +139,5 @@ export interface IFoo2 { prop: string };
export type talias1 = number; export type talias1 = number;
export type talias2 = number; export type talias2 = number;
export interface IFoo2 { prop: string } export interface IFoo2 { prop: string }
" "
`; `;

View File

@ -35,6 +35,7 @@ const myRequest = new Request(\"http://google.com\");
const a: Promise<string> = fetch(myRequest).then(response => response.text()); const a: Promise<string> = fetch(myRequest).then(response => response.text());
const b: Promise<string> = fetch(myRequest); const b: Promise<string> = fetch(myRequest);
// incorrect // incorrect
var myInit = { var myInit = {
method: \"GET\", method: \"GET\",
@ -44,6 +45,7 @@ var myInit = {
}; };
const c: Promise<Blob> = fetch(\"image.png\").then(response => response.blob()); const c: Promise<Blob> = fetch(\"image.png\").then(response => response.blob());
// correct // correct
const d: Promise<Blob> = fetch(\"image.png\"); // incorrect const d: Promise<Blob> = fetch(\"image.png\"); // incorrect
" "
@ -102,12 +104,15 @@ e.set(\"Content-Type\", \"image/jpeg\");
e.set(\"Content-Type\"); e.set(\"Content-Type\");
// not correct // not correct
e.set({ \"Content-Type\", \"image/jpeg\" }); e.set({ \"Content-Type\", \"image/jpeg\" });
// not correct // not correct
const f: Headers = e.append(\"Content-Type\", \"image/jpeg\"); const f: Headers = e.append(\"Content-Type\", \"image/jpeg\");
// not correct // not correct
const g: string = e.get(\"Content-Type\"); const g: string = e.get(\"Content-Type\");
// correct // correct
const h: number = e.get(\"Content-Type\"); const h: number = e.get(\"Content-Type\");
// not correct // not correct
for (let v of e) { for (let v of e) {
const [ i, j ]: [string, string] = v; // correct const [ i, j ]: [string, string] = v; // correct
@ -185,10 +190,12 @@ const c: Request = new Request(b);
const d: Request = new Request(c.clone()); const d: Request = new Request(c.clone());
// correct (doesn\'t make much sense though) // correct (doesn\'t make much sense though)
const e: Request = new Request(b, c); const e: Request = new Request(b, c);
// incorrect // incorrect
const f: Request = new Request({}); const f: Request = new Request({});
// incorrect // incorrect
const g: Request = new Request(\"http://example.org\", {}); const g: Request = new Request(\"http://example.org\", {});
// correct // correct
const h: Request = new Request(\"http://example.org\", { const h: Request = new Request(\"http://example.org\", {
method: \"GET\", method: \"GET\",
@ -196,6 +203,7 @@ const h: Request = new Request(\"http://example.org\", {
mode: \"cors\", mode: \"cors\",
cache: \"default\" cache: \"default\"
}); });
// correct // correct
const i: Request = new Request(\"http://example.org\", { const i: Request = new Request(\"http://example.org\", {
method: \"POST\", method: \"POST\",
@ -204,6 +212,7 @@ const i: Request = new Request(\"http://example.org\", {
mode: \"cors\", mode: \"cors\",
cache: \"default\" cache: \"default\"
}); });
// correct // correct
const j: Request = new Request(\"http://example.org\", { const j: Request = new Request(\"http://example.org\", {
method: \"GET\", method: \"GET\",
@ -211,6 +220,7 @@ const j: Request = new Request(\"http://example.org\", {
mode: \"cors\", mode: \"cors\",
cache: \"default\" cache: \"default\"
}); });
// incorrect - headers is string // incorrect - headers is string
const k: Request = new Request(\"http://example.org\", { const k: Request = new Request(\"http://example.org\", {
method: \"CONNECT\", method: \"CONNECT\",
@ -218,6 +228,7 @@ const k: Request = new Request(\"http://example.org\", {
mode: \"cors\", mode: \"cors\",
cache: \"default\" cache: \"default\"
}); });
// incorrect - CONNECT is forbidden // incorrect - CONNECT is forbidden
var l: boolean = h.bodyUsed; var l: boolean = h.bodyUsed;
@ -285,30 +296,37 @@ const a: Response = new Response();
const b: Response = new Response(new Blob()); const b: Response = new Response(new Blob());
// correct // correct
const c: Response = new Response(new FormData()); const c: Response = new Response(new FormData());
// correct // correct
const d: Response = new Response(new FormData(), { status: 404 }); const d: Response = new Response(new FormData(), { status: 404 });
// correct // correct
const e: Response = new Response(\"responsebody\", { status: \"404\" }); const e: Response = new Response(\"responsebody\", { status: \"404\" });
// incorrect // incorrect
const f: Response = new Response(\"responsebody\", { const f: Response = new Response(\"responsebody\", {
status: 404, status: 404,
headers: \"\'Content-Type\': \'image/jpeg\'\" headers: \"\'Content-Type\': \'image/jpeg\'\"
}); });
// incorrect // incorrect
const g: Response = new Response(\"responsebody\", { const g: Response = new Response(\"responsebody\", {
status: 404, status: 404,
headers: { \"Content-Type\": \"image/jpeg\" } headers: { \"Content-Type\": \"image/jpeg\" }
}); });
// correct // correct
const h: Response = new Response(\"responsebody\", { const h: Response = new Response(\"responsebody\", {
status: 404, status: 404,
headers: new Headers({ \"Content-Type\": \"image/jpeg\" }) headers: new Headers({ \"Content-Type\": \"image/jpeg\" })
}); });
// correct, if verbose // correct, if verbose
const i: Response = new Response({ const i: Response = new Response({
status: 404, status: 404,
headers: new Headers({ \"Content-Type\": \"image/jpeg\" }) headers: new Headers({ \"Content-Type\": \"image/jpeg\" })
}); });
// incorrect // incorrect
const ok: boolean = h.ok; const ok: boolean = h.ok;
const status: number = h.status; const status: number = h.status;
@ -376,12 +394,15 @@ e.set(\"key1\", \"value1\");
e.set(\"key1\"); e.set(\"key1\");
// not correct // not correct
e.set({ \"key1\", \"value1\" }); e.set({ \"key1\", \"value1\" });
// not correct // not correct
const f: URLSearchParams = e.append(\"key1\", \"value1\"); const f: URLSearchParams = e.append(\"key1\", \"value1\");
// not correct // not correct
const g: string = e.get(\"key1\"); const g: string = e.get(\"key1\");
// correct // correct
const h: number = e.get(\"key1\"); const h: number = e.get(\"key1\");
// not correct // not correct
for (let v of e) { for (let v of e) {
const [ i, j ]: [string, string] = v; // correct const [ i, j ]: [string, string] = v; // correct

View File

@ -35,7 +35,6 @@ module.exports = {fn: fix};
function eq(x: number, y: number) { function eq(x: number, y: number) {
return true; return true;
} }
function sub(x: number, y: number) { function sub(x: number, y: number) {
return 0; return 0;
} }

View File

@ -51,14 +51,17 @@ test.apply(\"\", [ \"\", 0 ]);
// wrong this is an error // wrong this is an error
test.apply(0, [ \"\", 0 ]); test.apply(0, [ \"\", 0 ]);
// error: lookup \`length\` on Number // error: lookup \`length\` on Number
// not enough arguments is an error (via incompatible RestT) // not enough arguments is an error (via incompatible RestT)
test.apply(\"\", [ \"\" ]); test.apply(\"\", [ \"\" ]);
// error: string ~> number // error: string ~> number
// mistyped arguments is an error // mistyped arguments is an error
test.apply(\"\", [ \"\", \"\" ]); test.apply(\"\", [ \"\", \"\" ]);
// error: string ~> number (2nd arg) // error: string ~> number (2nd arg)
test.apply(\"\", [ 0, 0 ]); test.apply(\"\", [ 0, 0 ]);
// error: number ~> string (1st arg) // error: number ~> string (1st arg)
// resolve args array from tvar // resolve args array from tvar
function f(args) { function f(args) {
@ -69,9 +72,11 @@ f([ \"\", 0 ]);
f([ \"\", \"\" ]); f([ \"\", \"\" ]);
// error: string ~> number (2nd arg) // error: string ~> number (2nd arg)
f([ 0, 0 ]); f([ 0, 0 ]);
// error: number ~> string (1st arg) // error: number ~> string (1st arg)
// expect array // expect array
test.apply(\"\", \"not array\"); test.apply(\"\", \"not array\");
// error: expect array of args // error: expect array of args
// expect 4 errors: // expect 4 errors:
// - lookup length on Number (because 0 is used as \`this\`) // - lookup length on Number (because 0 is used as \`this\`)
@ -166,14 +171,17 @@ test.call(\"\", \"\", 0);
// wrong this is an error // wrong this is an error
test.call(0, \"\", 0); test.call(0, \"\", 0);
// error: lookup \`length\` on Number // error: lookup \`length\` on Number
// not enough arguments is an error (via incompatible RestT) // not enough arguments is an error (via incompatible RestT)
test.call(\"\", \"\"); test.call(\"\", \"\");
// error: string ~> number // error: string ~> number
// mistyped arguments is an error // mistyped arguments is an error
test.call(\"\", \"\", \"\"); test.call(\"\", \"\", \"\");
// error: string ~> number (2nd arg) // error: string ~> number (2nd arg)
test.call(\"\", 0, 0); test.call(\"\", 0, 0);
// error: number ~> string (1st arg) // error: number ~> string (1st arg)
// resolve args array from tvar // resolve args array from tvar
function f(args) { function f(args) {
@ -184,6 +192,7 @@ f([ \"\", 0 ]);
f([ \"\", \"\" ]); f([ \"\", \"\" ]);
// error: string ~> number (2nd arg) // error: string ~> number (2nd arg)
f([ 0, 0 ]); f([ 0, 0 ]);
// error: number ~> string (1st arg) // error: number ~> string (1st arg)
// expect 3 errors: // expect 3 errors:
// - lookup length on Number (0 used as \`this\`) // - lookup length on Number (0 used as \`this\`)
@ -315,6 +324,7 @@ let tests = [
(y.length: void); (y.length: void);
// error, it\'s a number // error, it\'s a number
(z.length: void); (z.length: void);
// error, it\'s a number // error, it\'s a number
(x.name: void); (x.name: void);
// error, it\'s a string // error, it\'s a string
@ -330,12 +340,14 @@ let tests = [
y.length = \"foo\"; y.length = \"foo\";
// error, it\'s a number // error, it\'s a number
z.length = \"foo\"; z.length = \"foo\";
// error, it\'s a number // error, it\'s a number
x.name = 123; x.name = 123;
// error, it\'s a string // error, it\'s a string
y.name = 123; y.name = 123;
// error, it\'s a string // error, it\'s a string
z.name = 123; z.name = 123;
// error, it\'s a string // error, it\'s a string
// Non-(Function.prototype) properties on a \`Function\` type should be \`any\` // Non-(Function.prototype) properties on a \`Function\` type should be \`any\`
(z.foo: number); (z.foo: number);

View File

@ -231,6 +231,7 @@ var examples = new GeneratorExamples();
for (var x of examples.infer_stmt()) { for (var x of examples.infer_stmt()) {
(x: string); (x: string);
} }
// error: number ~> string // error: number ~> string
var infer_stmt_next = examples.infer_stmt().next(0).value; var infer_stmt_next = examples.infer_stmt().next(0).value;
// error: number ~> boolean // error: number ~> boolean
@ -259,6 +260,7 @@ for (var x of examples.delegate_yield_generator()) {
} }
examples.delegate_next_iterable([]).next(\"\"); examples.delegate_next_iterable([]).next(\"\");
// error: Iterator has no next value // error: Iterator has no next value
for (var x of examples.delegate_yield_iterable([])) { for (var x of examples.delegate_yield_iterable([])) {
(x: string); // error: number ~> string (x: string); // error: number ~> string
@ -303,8 +305,10 @@ var examples = new GeneratorExamples();
for (var x of examples.infer_stmt()) { for (var x of examples.infer_stmt()) {
(x: string); (x: string);
} }
// error: number ~> string // error: number ~> string
var infer_stmt_next = examples.infer_stmt().next(0).value; var infer_stmt_next = examples.infer_stmt().next(0).value;
// error: number ~> boolean // error: number ~> boolean
if (typeof infer_stmt_next === \"undefined\") { if (typeof infer_stmt_next === \"undefined\") {
} else if (typeof infer_stmt_next === \"number\") { } else if (typeof infer_stmt_next === \"number\") {
@ -544,6 +548,7 @@ function* delegate_next_iterable(xs: Array<number>) {
yield* xs; yield* xs;
} }
delegate_next_iterable([]).next(\"\"); delegate_next_iterable([]).next(\"\");
// error: Iterator has no next value // error: Iterator has no next value
function* delegate_yield_iterable(xs: Array<number>) { function* delegate_yield_iterable(xs: Array<number>) {
yield* xs; yield* xs;

View File

@ -44,15 +44,18 @@ var Parent = require(\"./Parent\");
let ParentFoo; let ParentFoo;
({ ParentFoo } = Parent); ({ ParentFoo } = Parent);
ParentFoo; ParentFoo;
// Points to lval in line above this // Points to lval in line above this
// Follows assignment on simple/\"non-destructuring\" patterns // Follows assignment on simple/\"non-destructuring\" patterns
let ParentFoo2; let ParentFoo2;
ParentFoo2 = Parent; ParentFoo2 = Parent;
ParentFoo2; ParentFoo2;
// Points to LHS of line above this // Points to LHS of line above this
// Follows assignment with declaration // Follows assignment with declaration
let ParentFoo3 = Parent; let ParentFoo3 = Parent;
ParentFoo3; ParentFoo3;
// Points to LHS of line above this // Points to LHS of line above this
// Follows non-destructured property access of \`require(\'Parent\')\` // Follows non-destructured property access of \`require(\'Parent\')\`
let foo = require(\"./Parent\").ParentFoo.foo; let foo = require(\"./Parent\").ParentFoo.foo;

View File

@ -101,6 +101,7 @@ class Foo {
} }
set propWithMismatchingGetterAndSetter(x: string) { set propWithMismatchingGetterAndSetter(x: string) {
} }
// doesn\'t match getter (OK) // doesn\'t match getter (OK)
propOverriddenWithGetter: number; propOverriddenWithGetter: number;
get propOverriddenWithGetter() { get propOverriddenWithGetter() {
@ -121,6 +122,7 @@ var testGetterNoError2: number = foo.goodGetterWithAnnotation;
var testGetterWithError1: string = foo.goodGetterNoAnnotation; var testGetterWithError1: string = foo.goodGetterNoAnnotation;
// Error number ~> string // Error number ~> string
var testGetterWithError2: string = foo.goodGetterWithAnnotation; var testGetterWithError2: string = foo.goodGetterWithAnnotation;
// Error number ~> string // Error number ~> string
// Test setting properties with getters // Test setting properties with getters
foo.goodSetterNoAnnotation = 123; foo.goodSetterNoAnnotation = 123;
@ -130,8 +132,10 @@ foo.goodSetterWithAnnotation = 123;
foo.goodSetterNoAnnotation = \"hello\"; foo.goodSetterNoAnnotation = \"hello\";
// Error string ~> number // Error string ~> number
foo.goodSetterWithAnnotation = \"hello\"; foo.goodSetterWithAnnotation = \"hello\";
// Error string ~> number // Error string ~> number
var testSubtypingGetterAndSetter: number = foo.propWithSubtypingGetterAndSetter; var testSubtypingGetterAndSetter: number = foo.propWithSubtypingGetterAndSetter;
// Error ?number ~> number // Error ?number ~> number
var testPropOverridenWithGetter: number = foo.propOverriddenWithGetter; var testPropOverridenWithGetter: number = foo.propOverriddenWithGetter;
// Error string ~> number // Error string ~> number
@ -261,6 +265,7 @@ var testGetterNoError2: number = obj.goodGetterWithAnnotation;
var testGetterWithError1: string = obj.goodGetterNoAnnotation; var testGetterWithError1: string = obj.goodGetterNoAnnotation;
// Error number ~> string // Error number ~> string
var testGetterWithError2: string = obj.goodGetterWithAnnotation; var testGetterWithError2: string = obj.goodGetterWithAnnotation;
// Error number ~> string // Error number ~> string
// Test setting properties with getters // Test setting properties with getters
obj.goodSetterNoAnnotation = 123; obj.goodSetterNoAnnotation = 123;
@ -269,13 +274,16 @@ obj.goodSetterWithAnnotation = 123;
obj.goodSetterNoAnnotation = \"hello\"; obj.goodSetterNoAnnotation = \"hello\";
// Error string ~> number // Error string ~> number
obj.goodSetterWithAnnotation = \"hello\"; obj.goodSetterWithAnnotation = \"hello\";
// Error string ~> number // Error string ~> number
var testSubtypingGetterAndSetter: number = obj.propWithSubtypingGetterAndSetter; var testSubtypingGetterAndSetter: number = obj.propWithSubtypingGetterAndSetter;
// Error ?number ~> number // Error ?number ~> number
// When building this feature, it was tempting to flow the setter into the // 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. // 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 // This example shows the danger of using the getter\'s type
obj.exampleOfOrderOfGetterAndSetter = new C(); obj.exampleOfOrderOfGetterAndSetter = new C();
// Error C ~> B // Error C ~> B
// And this example shows the danger of using the setter\'s type. // And this example shows the danger of using the setter\'s type.
var testExampleOrOrderOfGetterAndSetterReordered: number = obj.exampleOfOrderOfGetterAndSetterReordered; // Error A ~> B var testExampleOrOrderOfGetterAndSetterReordered: number = obj.exampleOfOrderOfGetterAndSetterReordered; // Error A ~> B
@ -402,15 +410,12 @@ class Base {
get get(): B { get get(): B {
return this.x; return this.x;
} }
set set(value: B): void { set set(value: B): void {
this.x = value; this.x = value;
} }
get getset(): B { get getset(): B {
return this.x; return this.x;
} }
set getset(value: B): void { set getset(value: B): void {
this.x = value; this.x = value;
} }

View File

@ -133,7 +133,6 @@ export function givesAFoo3Obj(): AliasFoo3 {
} }
}; };
} }
" "
`; `;
@ -274,6 +273,7 @@ var a1: ClassFoo1 = foo1Inst;
var a2: number = foo1Inst; var a2: number = foo1Inst;
// Error: ClassFoo1 ~> number // Error: ClassFoo1 ~> number
new ClassFoo1(); new ClassFoo1();
// Error: ClassFoo1 is not a value-identifier // Error: ClassFoo1 is not a value-identifier
/////////////////////////////////////////////// ///////////////////////////////////////////////
// == Importing Class Type (Named Export) == // // == Importing Class Type (Named Export) == //
@ -285,6 +285,7 @@ var b1: ClassFoo2 = foo2Inst;
var b2: number = foo2Inst; var b2: number = foo2Inst;
// Error: ClassFoo2 ~> number // Error: ClassFoo2 ~> number
new ClassFoo2(); new ClassFoo2();
// Error: ClassFoo2 is not a value-identifier // Error: ClassFoo2 is not a value-identifier
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
// == Importing Class Type (CJS Default Export) == // // == Importing Class Type (CJS Default Export) == //
@ -293,6 +294,7 @@ import type ClassFoo3T from \"./ExportCJSDefault_Class\";
import ClassFoo3 from \"./ExportCJSDefault_Class\"; import ClassFoo3 from \"./ExportCJSDefault_Class\";
var c1: ClassFoo3T = new ClassFoo3(); var c1: ClassFoo3T = new ClassFoo3();
new ClassFoo3T(); new ClassFoo3T();
// Error: ClassFoo3 is not a value-identifier // Error: ClassFoo3 is not a value-identifier
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
// == Importing Class Type (CJS Named Export) == // // == Importing Class Type (CJS Named Export) == //
@ -307,6 +309,7 @@ new ClassFoo4();
// Error: ClassFoo4 is not a value-identifier // Error: ClassFoo4 is not a value-identifier
// TODO: this errors correctly, but the message is just \'can\'t resolve name\' // TODO: this errors correctly, but the message is just \'can\'t resolve name\'
var d3: typeof ClassFoo5 = foo5Inst; var d3: typeof ClassFoo5 = foo5Inst;
// Error: Can\'t typeof a type alias // Error: Can\'t typeof a type alias
//////////////////////////////////////////// ////////////////////////////////////////////
// == Import Type Alias (Named Export) == // // == Import Type Alias (Named Export) == //
@ -317,6 +320,7 @@ var e1: AliasFoo3 = givesAFoo3Obj();
var e2: number = givesAFoo3Obj(); var e2: number = givesAFoo3Obj();
// Error: AliasFoo3 ~> number // Error: AliasFoo3 ~> number
var e3: typeof AliasFoo3 = givesAFoo3Obj(); var e3: typeof AliasFoo3 = givesAFoo3Obj();
// Error: Can\'t typeof a type alias // Error: Can\'t typeof a type alias
////////////////////////////////////////////// //////////////////////////////////////////////
// == Import Type Alias (Default Export) == // // == Import Type Alias (Default Export) == //
@ -328,6 +332,7 @@ var e3: typeof AliasFoo3 = givesAFoo3Obj();
// == Import Type With Non-Alias Compatible Value == // // == Import Type With Non-Alias Compatible Value == //
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
import type { numValue } from \"./ExportsANumber\"; import type { numValue } from \"./ExportsANumber\";
// Error: Cannot import-type a number value // Error: Cannot import-type a number value
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// == Regression Test: https://github.com/facebook/flow/issues/359 == // // == Regression Test: https://github.com/facebook/flow/issues/359 == //

View File

@ -132,7 +132,6 @@ export function givesAFoo3Obj(): AliasFoo3 {
} }
}; };
} }
" "
`; `;
@ -305,6 +304,7 @@ var a1: ClassFoo1T = ClassFoo1;
var a2: ClassFoo1T = new ClassFoo1(); var a2: ClassFoo1T = new ClassFoo1();
// Error: ClassFoo1 (inst) ~> ClassFoo1 (class) // Error: ClassFoo1 (inst) ~> ClassFoo1 (class)
new ClassFoo1T(); new ClassFoo1T();
// Error: ClassFoo1T is not bound to a value // Error: ClassFoo1T is not bound to a value
///////////////////////////////////////////////// /////////////////////////////////////////////////
// == Importing Class Typeof (Named Export) == // // == Importing Class Typeof (Named Export) == //
@ -316,6 +316,7 @@ var b1: ClassFoo2T = ClassFoo2;
var b2: ClassFoo2T = new ClassFoo2(); var b2: ClassFoo2T = new ClassFoo2();
// Error: ClassFoo2 (inst) ~> ClassFoo2 (class) // Error: ClassFoo2 (inst) ~> ClassFoo2 (class)
new ClassFoo2T(); new ClassFoo2T();
// Error: ClassFoo2T is not bound to a value // Error: ClassFoo2T is not bound to a value
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
// == Importing Class Typeof (CJS Default Export) == // // == Importing Class Typeof (CJS Default Export) == //
@ -325,6 +326,7 @@ import ClassFoo3 from \"./ExportCJSDefault_Class\";
var c1: ClassFoo3T = ClassFoo3; var c1: ClassFoo3T = ClassFoo3;
var c2: ClassFoo3T = new ClassFoo3(); var c2: ClassFoo3T = new ClassFoo3();
// Error: ClassFoo3 (inst) ~> ClassFoo3 (class) // Error: ClassFoo3 (inst) ~> ClassFoo3 (class)
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
// == Importing Class Typeof (CJS Named Export) == // // == Importing Class Typeof (CJS Named Export) == //
@ -334,11 +336,13 @@ import { ClassFoo4 } from \"./ExportCJSNamed_Class\";
var d1: ClassFoo4T = ClassFoo4; var d1: ClassFoo4T = ClassFoo4;
var d2: ClassFoo4T = new ClassFoo4(); var d2: ClassFoo4T = new ClassFoo4();
// Error: ClassFoo4 (inst) ~> ClassFoo4 (class) // Error: ClassFoo4 (inst) ~> ClassFoo4 (class)
////////////////////////////////////////////// //////////////////////////////////////////////
// == Import Typeof Alias (Named Export) == // // == Import Typeof Alias (Named Export) == //
////////////////////////////////////////////// //////////////////////////////////////////////
import typeof { AliasFoo3 } from \"./ExportNamed_Alias\"; import typeof { AliasFoo3 } from \"./ExportNamed_Alias\";
// Error: Can\'t \`import typeof\` type aliases! // Error: Can\'t \`import typeof\` type aliases!
//////////////////////////////////////////////// ////////////////////////////////////////////////
// == Import Typeof Alias (Default Export) == // // == Import Typeof Alias (Default Export) == //
@ -353,6 +357,7 @@ import typeof num_default from \"./ExportDefault_Number\";
var f1: num_default = 42; var f1: num_default = 42;
var f2: num_default = \"asdf\"; var f2: num_default = \"asdf\";
// Error: string ~> number // Error: string ~> number
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
// == Import Typeof With Non-Class Value (Named Export) == // // == Import Typeof With Non-Class Value (Named Export) == //
@ -361,6 +366,7 @@ import typeof { num as num_named } from \"./ExportNamed_Number\";
var g1: num_named = 42; var g1: num_named = 42;
var g2: num_named = \"asdf\"; var g2: num_named = \"asdf\";
// Error: string ~> number // Error: string ~> number
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
// == Import Typeof With Non-Class Value (CJS Default Export) == // // == Import Typeof With Non-Class Value (CJS Default Export) == //
@ -369,6 +375,7 @@ import typeof num_cjs_default from \"./ExportCJSDefault_Number\";
var h1: num_cjs_default = 42; var h1: num_cjs_default = 42;
var h2: num_cjs_default = \"asdf\"; var h2: num_cjs_default = \"asdf\";
// Error: string ~> number // Error: string ~> number
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// == Import Typeof With Non-Class Value (CJS Named Export) == // // == Import Typeof With Non-Class Value (CJS Named Export) == //
@ -377,6 +384,7 @@ import typeof { num as num_cjs_named } from \"./ExportCJSNamed_Number\";
var i1: num_cjs_named = 42; var i1: num_cjs_named = 42;
var i2: num_cjs_named = \"asdf\"; var i2: num_cjs_named = \"asdf\";
// Error: string ~> number // Error: string ~> number
/////////////////////////////////////////////// ///////////////////////////////////////////////
// == Import Typeof ModuleNamespaceObject == // // == Import Typeof ModuleNamespaceObject == //

View File

@ -93,7 +93,6 @@ function foo1(x: Array<number> | number) {
class X1 { class X1 {
foo: number; foo: number;
} }
class X2 { class X2 {
foo: string; foo: string;
} }
@ -117,7 +116,6 @@ function consumer2(b) {
class Y1 { class Y1 {
bar: X1; bar: X1;
} }
class Y2 { class Y2 {
bar: X2; bar: X2;
} }
@ -141,7 +139,6 @@ function consumer4(b) {
class Z1 { class Z1 {
baz: Y1; baz: Y1;
} }
class Z2 { class Z2 {
baz: Y2; baz: Y2;
} }

View File

@ -54,6 +54,7 @@ var x: string = new C().x;
interface I { x: number } interface I { x: number }
var i = new I(); var i = new I();
// error // error
function testInterfaceName(o: I) { function testInterfaceName(o: I) {
(o.name: string); (o.name: string);
@ -138,9 +139,12 @@ interface L extends J, K { y: string }
function foo(l: L) { function foo(l: L) {
l.x; l.x;
l.y; l.y;
l.z; l.z;
} }
// error: z not found in L // error: z not found in L
// interface + multiple inheritance is similar to object type + intersection // interface + multiple inheritance is similar to object type + intersection
type M = { y: string } & J & { z: boolean }; type M = { y: string } & J & { z: boolean };
@ -188,6 +192,7 @@ new C().bar((x: string) => { }); // error, number ~/~> string
interface I { foo(x: number): void } interface I { foo(x: number): void }
(function foo(x: number) { (function foo(x: number) {
}: I); }: I);
// error, property \`foo\` not found function // error, property \`foo\` not found function
declare class C { bar(i: I): void, bar(f: (x: number) => void): void } declare class C { bar(i: I): void, bar(f: (x: number) => void): void }

View File

@ -221,6 +221,7 @@ var b: B = a;
// intersection of dictionary types: // intersection of dictionary types:
declare var c: C; declare var c: C;
var d: D = c; var d: D = c;
// ok // ok
// dict type mismatch // dict type mismatch
type E = { [key: string]: string }; type E = { [key: string]: string };

View File

@ -194,7 +194,6 @@ function mapTest1(map: Map<string, number>): Iterable<[string, number]> {
function mapTest2<K, V>(map: Map<K, V>): Iterable<[K, V]> { function mapTest2<K, V>(map: Map<K, V>): Iterable<[K, V]> {
return map; return map;
} }
function mapTest3(map: Map<string, number>): Iterable<*> { function mapTest3(map: Map<string, number>): Iterable<*> {
return map; return map;
} }
@ -230,7 +229,6 @@ function setTest1(set: Set<string>): Iterable<string> {
function setTest2<T>(set: Set<T>): Iterable<T> { function setTest2<T>(set: Set<T>): Iterable<T> {
return set; return set;
} }
function setTest3(set: Set<string>): Iterable<*> { function setTest3(set: Set<string>): Iterable<*> {
return set; return set;
} }
@ -266,6 +264,7 @@ exports[`test variance.js 1`] = `
/* @flow */ /* @flow */
(([]: Array<string>): Iterable<?string>); (([]: Array<string>): Iterable<?string>);
// ok, Iterable<+T> // ok, Iterable<+T>
(([]: Array<string>).values(): Iterable<?string>); // ok, Iterator<+T> (([]: Array<string>).values(): Iterable<?string>); // ok, Iterator<+T>
" "

View File

@ -31,6 +31,7 @@ class CustomComponent extends React.Component {
var a: React.Element<{ prop: string }> = <CustomComponent prop=\"asdf\" />; var a: React.Element<{ prop: string }> = <CustomComponent prop=\"asdf\" />;
var b: React.Element<{ prop1: string }> = <CustomComponent prop=\"asdf\" />; var b: React.Element<{ prop1: string }> = <CustomComponent prop=\"asdf\" />;
// Error: Props<{prop}> ~> Props<{prop1}> // Error: Props<{prop}> ~> Props<{prop1}>
// Since intrinsics are typed as \`any\` out of the box, we can pass any // Since intrinsics are typed as \`any\` out of the box, we can pass any
// attributes to intrinsics! // attributes to intrinsics!
@ -79,10 +80,12 @@ var Str: string = \"str\";
<Bad />; <Bad />;
/* This is fine*/ /* This is fine*/
<Str />; <Str />;
// This is fine // This is fine
React.createElement(\"div\", {}); React.createElement(\"div\", {});
// This is fine // This is fine
React.createElement(\"bad\", {}); React.createElement(\"bad\", {});
/* This is fine*/ /* This is fine*/
<Div id={42} />; // This is fine <Div id={42} />; // This is fine
" "

View File

@ -27,6 +27,7 @@ class CustomComponent extends React.Component {
var a: React.Element<{ prop: string }> = <CustomComponent prop=\"asdf\" />; var a: React.Element<{ prop: string }> = <CustomComponent prop=\"asdf\" />;
var b: React.Element<{ prop1: string }> = <CustomComponent prop=\"asdf\" />; var b: React.Element<{ prop1: string }> = <CustomComponent prop=\"asdf\" />;
/* Error: Props<{prop}> ~> Props<{prop1}>*/ /* Error: Props<{prop}> ~> Props<{prop1}>*/
<div id=\"asdf\" />; <div id=\"asdf\" />;
<div id={42} />; <div id={42} />;
@ -71,12 +72,14 @@ var Str: string = \"str\";
<Bad />; <Bad />;
/* Error: \'bad\' not in JSXIntrinsics*/ /* Error: \'bad\' not in JSXIntrinsics*/
<Str />; <Str />;
// Error: string ~> keys of JSXIntrinsics // Error: string ~> keys of JSXIntrinsics
React.createElement(\"div\", {}); React.createElement(\"div\", {});
// This is fine // This is fine
React.createElement(\"bad\", {}); React.createElement(\"bad\", {});
// Error: \'bad\' not in JSXIntrinsics // Error: \'bad\' not in JSXIntrinsics
React.createElement(Str, {}); React.createElement(Str, {});
/* Error: string ~> keys of JSXIntrinsics*/ /* Error: string ~> keys of JSXIntrinsics*/
/* TODO: Make this an error*/ /* TODO: Make this an error*/
<Div id={42} />; // Not an error but should be eventually <Div id={42} />; // Not an error but should be eventually

View File

@ -54,6 +54,7 @@ function testKeysOfObject(str: string, lit: \"hi\") {
(str: $Keys<Object>); // No error, truthy string should be fine (str: $Keys<Object>); // No error, truthy string should be fine
} }
(\"hi\": $Keys<Object>); (\"hi\": $Keys<Object>);
// String literal should be fine // String literal should be fine
(123: $Keys<Object>); // Error: number -> keys of Object (123: $Keys<Object>); // Error: number -> keys of Object
} }
@ -66,6 +67,7 @@ function testKeysOfStrDict(str: string, lit: \"hi\") {
(str: $Keys<StrDict>); // No error, truthy string should be fine (str: $Keys<StrDict>); // No error, truthy string should be fine
} }
(\"hi\": $Keys<StrDict>); (\"hi\": $Keys<StrDict>);
// String literal should be fine // String literal should be fine
(123: $Keys<StrDict>); // Error: number -> keys of StrDict (123: $Keys<StrDict>); // Error: number -> keys of StrDict
} }
@ -80,6 +82,7 @@ function testKeysOfStrLitDict(str: string, lit: \"hi\") {
(\"hi\": $Keys<StrLitDict>); (\"hi\": $Keys<StrLitDict>);
// The right string literal is allowed // The right string literal is allowed
(\"bye\": $Keys<StrLitDict>); (\"bye\": $Keys<StrLitDict>);
// Error: The wrong string literal is not allowed // Error: The wrong string literal is not allowed
(123: $Keys<StrLitDict>); // Error: number -> keys of StrLitDict (123: $Keys<StrLitDict>); // Error: number -> keys of StrLitDict
} }
@ -92,6 +95,7 @@ function testKeysOfOtherObj(str: string, lit: \"hi\") {
(str: $Keys<ObjLit>); // Error: truthy string -> keys of ObjLit (str: $Keys<ObjLit>); // Error: truthy string -> keys of ObjLit
} }
(\"hi\": $Keys<ObjLit>); (\"hi\": $Keys<ObjLit>);
// String literal should be fine // String literal should be fine
(123: $Keys<ObjLit>); // Error: number -> keys of ObjLit (123: $Keys<ObjLit>); // Error: number -> keys of ObjLit
} }

View File

@ -75,6 +75,7 @@ class C {
(new C().bar: boolean); (new C().bar: boolean);
// last wins // last wins
(new C().qux: boolean); (new C().qux: boolean);
// weird outlier where last doesn\'t win in classes // weird outlier where last doesn\'t win in classes
// Objects // Objects
const o = { const o = {

View File

@ -41,20 +41,24 @@ function foo(x: $Keys<typeof APIKeys>) {
} }
foo(\"AGE\"); foo(\"AGE\");
foo(\"LOCATION\"); foo(\"LOCATION\");
// error // error
function bar(x: $Keys<{ age: number }>) { function bar(x: $Keys<{ age: number }>) {
} }
bar(APIKeys.AGE); bar(APIKeys.AGE);
// not an error: APIKeys.AGE = \"age\" // not an error: APIKeys.AGE = \"age\"
bar(APIKeys.NAME); bar(APIKeys.NAME);
// error: since \"NAME\" is not in the smaller enum // error: since \"NAME\" is not in the smaller enum
var object = {}; var object = {};
object[APIKeys.AGE] = 123; object[APIKeys.AGE] = 123;
// i.e., object.age = 123 // i.e., object.age = 123
object[APIKeys.NAME] = \"FOO\"; object[APIKeys.NAME] = \"FOO\";
// i.e., object.name = \"FOO\" // i.e., object.name = \"FOO\"
var age: number = object[APIKeys.AGE]; var age: number = object[APIKeys.AGE];
var name: number = object[APIKeys.NAME]; var name: number = object[APIKeys.NAME];
// error: object.name is a string // error: object.name is a string
var indices = { red: 0, green: 1, blue: 2 }; var indices = { red: 0, green: 1, blue: 2 };
var tuple = [ 42, \"hello\", false ]; var tuple = [ 42, \"hello\", false ];

View File

@ -53,6 +53,7 @@ C.bar.x;
import { Foo } from \"./exports_optional_prop\"; import { Foo } from \"./exports_optional_prop\";
const foo = new Foo(); const foo = new Foo();
(foo.bar(): string); (foo.bar(): string);
// error, could be undefined // error, could be undefined
function f(x) { function f(x) {
(x.bar(): string); // error. caused by \`f(foo)\`; annotate x to track it down. (x.bar(): string); // error. caused by \`f(foo)\`; annotate x to track it down.

View File

@ -48,6 +48,7 @@ function g(x: string) {
//function f(x:number) { g(x); return x; } //function f(x:number) { g(x); return x; }
function f(x: number): number { function f(x: number): number {
g(x); g(x);
return x; return x;
} }

View File

@ -16,6 +16,7 @@ var test1 = A.bar;
// Error bar doesn\'t exist // Error bar doesn\'t exist
var test2: string = A.name; var test2: string = A.name;
var test3: number = A.name; var test3: number = A.name;
// Error string ~> number // Error string ~> number
var a = new A(); var a = new A();
var test4 = a.constructor.bar; var test4 = a.constructor.bar;

View File

@ -67,6 +67,7 @@ let tests = [
// 1 error // 1 error
hmac.update(buf); hmac.update(buf);
hmac.update(buf, \"utf8\"); hmac.update(buf, \"utf8\");
// 1 error: no encoding when passing a buffer // 1 error: no encoding when passing a buffer
// it\'s also chainable // it\'s also chainable
(hmac.update(\"some data to hash\").update(buf).digest(): Buffer); (hmac.update(\"some data to hash\").update(buf).digest(): Buffer);

View File

@ -55,12 +55,15 @@ fs.readFile(\"file.exp\", {}, (_, data) => {
/* readFileSync */ /* readFileSync */
(fs.readFileSync(\"file.exp\"): Buffer); (fs.readFileSync(\"file.exp\"): Buffer);
(fs.readFileSync(\"file.exp\"): string); (fs.readFileSync(\"file.exp\"): string);
// error // error
(fs.readFileSync(\"file.exp\", \"blah\"): string); (fs.readFileSync(\"file.exp\", \"blah\"): string);
(fs.readFileSync(\"file.exp\", \"blah\"): Buffer); (fs.readFileSync(\"file.exp\", \"blah\"): Buffer);
// error // error
(fs.readFileSync(\"file.exp\", { encoding: \"blah\" }): string); (fs.readFileSync(\"file.exp\", { encoding: \"blah\" }): string);
(fs.readFileSync(\"file.exp\", { encoding: \"blah\" }): Buffer); (fs.readFileSync(\"file.exp\", { encoding: \"blah\" }): Buffer);
// error // error
(fs.readFileSync(\"file.exp\", {}): Buffer); (fs.readFileSync(\"file.exp\", {}): Buffer);
(fs.readFileSync(\"file.exp\", {}): string); // error (fs.readFileSync(\"file.exp\", {}): string); // error

View File

@ -31,16 +31,20 @@ let data = require(\"./package/index.json\");
(data.foo.bar: void); (data.foo.bar: void);
// error, should be boolean // error, should be boolean
(data.abc: boolean); (data.abc: boolean);
// error, should be ?string // error, should be ?string
let data2 = require(\"./package\"); let data2 = require(\"./package\");
(data2.baz: void); (data2.baz: void);
// error, should be string // error, should be string
let data3 = require(\"./package2\"); let data3 = require(\"./package2\");
(data3.foo: void); (data3.foo: void);
// error, should be number (not string! index.js wins) // error, should be number (not string! index.js wins)
let data4 = require(\"./json_array\"); let data4 = require(\"./json_array\");
(data4: Array<number>); (data4: Array<number>);
(data4: void); (data4: void);
// error, should be Array<number> // error, should be Array<number>
(require(\"./json_string\"): void); (require(\"./json_string\"): void);
// error, should be string // error, should be string

View File

@ -22,10 +22,12 @@ var os = require(\"os\");
var u1 = os.userInfo(); var u1 = os.userInfo();
(u1.username: string); (u1.username: string);
(u1.username: Buffer); (u1.username: Buffer);
// error // error
var u2 = os.userInfo({ encoding: \"utf8\" }); var u2 = os.userInfo({ encoding: \"utf8\" });
(u2.username: string); (u2.username: string);
(u2.username: Buffer); (u2.username: Buffer);
// error // error
var u3 = os.userInfo({ encoding: \"buffer\" }); var u3 = os.userInfo({ encoding: \"buffer\" });
(u3.username: string); (u3.username: string);

View File

@ -53,6 +53,7 @@ var x = bar();
if (x != null) qux(x); if (x != null) qux(x);
// x: ?string | null // x: ?string | null
if (x != null) corge(x); if (x != null) corge(x);
// x: ?string | null // x: ?string | null
function grault() { function grault() {
x = null; x = null;

View File

@ -121,6 +121,7 @@ function bar(f: () => void) {
} }
bar(foo); bar(foo);
// error, since \`this\` is used non-trivially in \`foo\` // error, since \`this\` is used non-trivially in \`foo\`
function qux(o: { f(): void }) { function qux(o: { f(): void }) {
o.f(); // passing o as \`this\` o.f(); // passing o as \`this\`

View File

@ -76,6 +76,7 @@ var decl_export_: { foo: any, bar: any } = Object.assign({}, export_);
let anyObj: Object = {}; let anyObj: Object = {};
Object.assign(anyObj, anyObj); Object.assign(anyObj, anyObj);
// makes sure this terminates // makes sure this terminates
module.exports = export_; module.exports = export_;
" "
@ -188,6 +189,7 @@ class Bar extends Foo {
var sealed = { one: \"one\", two: \"two\" }; var sealed = { one: \"one\", two: \"two\" };
(Object.keys(sealed): Array<\"one\" | \"two\">); (Object.keys(sealed): Array<\"one\" | \"two\">);
(Object.keys(sealed): void); (Object.keys(sealed): void);
// error, Array<string> // error, Array<string>
var unsealed = {}; var unsealed = {};
Object.keys(unsealed).forEach(k => { Object.keys(unsealed).forEach(k => {
@ -201,6 +203,7 @@ Object.keys(dict).forEach(k => {
var any: Object = {}; var any: Object = {};
(Object.keys(any): Array<number>); (Object.keys(any): Array<number>);
// error, Array<string> // error, Array<string>
class Foo { class Foo {
prop: string; prop: string;
@ -209,6 +212,7 @@ class Foo {
} }
// constructor and foo not enumerable // constructor and foo not enumerable
(Object.keys(new Foo()): Array<\"error\">); (Object.keys(new Foo()): Array<\"error\">);
// error: prop ~> error // error: prop ~> error
class Bar extends Foo { class Bar extends Foo {
bar_prop: string; bar_prop: string;
@ -436,6 +440,7 @@ var y = new Foo();
// call // call
takesAString(a.toString()); takesAString(a.toString());
d.toString(); d.toString();
// ok, even though dict specifies strings, this is a function // ok, even though dict specifies strings, this is a function
// get // get
var aToString: () => string = a.toString; var aToString: () => string = a.toString;
@ -475,6 +480,7 @@ takesAString(y.toString());
(123).toString(\"foo\"); (123).toString(\"foo\");
// error // error
(123).toString(null); (123).toString(null);
// error // error
// //
// hasOwnProperty // hasOwnProperty

View File

@ -86,6 +86,7 @@ var good: number = A.Good.foo();
var f = A.Bad.foo; var f = A.Bad.foo;
// Property access is fine // Property access is fine
var bad_: number = f(); var bad_: number = f();
// Calling the function is fine // Calling the function is fine
var bad: number = A.Bad.foo(); // Method call is not fine var bad: number = A.Bad.foo(); // Method call is not fine
/* /*

View File

@ -24,8 +24,10 @@ var xx : { x: number } = Object.freeze({ x: \"error\" })
var foo = Object.freeze({ bar: \"12345\" }); var foo = Object.freeze({ bar: \"12345\" });
foo.bar = \"23456\"; foo.bar = \"23456\";
// error // error
Object.assign(foo, { bar: \"12345\" }); Object.assign(foo, { bar: \"12345\" });
// error // error
var baz = { baz: 12345 }; var baz = { baz: 12345 };
var bliffl = Object.freeze({ bar: \"12345\", ...baz }); var bliffl = Object.freeze({ bar: \"12345\", ...baz });
@ -39,6 +41,7 @@ bliffl.constructor = baz;
// error // error
bliffl.toString = function() { bliffl.toString = function() {
}; };
// error // error
baz.baz = 0; baz.baz = 0;

View File

@ -29,6 +29,7 @@ var z = Object(123); // error (next line makes this not match any signatures)
(Object(undefined): {}); (Object(undefined): {});
(Object(void 0): {}); (Object(void 0): {});
(Object(undefined): Number); (Object(undefined): Number);
// error // error
var x = Object(null); var x = Object(null);
x.foo = \"bar\"; x.foo = \"bar\";
@ -82,11 +83,13 @@ x[123] = false;
x[\"foo\" + \"bar\"] = \"derp\"; x[\"foo\" + \"bar\"] = \"derp\";
// ok since we can\'t tell // ok since we can\'t tell
(x[\`foo\`]: string); (x[\`foo\`]: string);
// error, key doesn\'t exist // error, key doesn\'t exist
var y: { foo: string } = { foo: \"bar\" }; var y: { foo: string } = { foo: \"bar\" };
y[\"foo\"] = 123; y[\"foo\"] = 123;
// error, number !~> string // error, number !~> string
y[\"bar\"] = \"abc\"; y[\"bar\"] = \"abc\";
// error, property not found // error, property not found
(y[\"hasOwnProperty\"]: string); // error, prototype method is not a string (y[\"hasOwnProperty\"]: string); // error, prototype method is not a string
" "

View File

@ -26,6 +26,7 @@ var o = keyMirror({ FOO: null, BAR: null });
(o.FOO: \"FOO\"); (o.FOO: \"FOO\");
// ok // ok
(o.FOO: \"BAR\"); (o.FOO: \"BAR\");
// error, \'FOO\' incompatible with \'BAR\' // error, \'FOO\' incompatible with \'BAR\'
promiseAllByKey({ foo: Promise.resolve(0), bar: \"bar\" }).then(o => { promiseAllByKey({ foo: Promise.resolve(0), bar: \"bar\" }).then(o => {
(o.foo: string); (o.foo: string);

View File

@ -175,6 +175,7 @@ foo();
function qux(x = \"hello\", ...y): string { function qux(x = \"hello\", ...y): string {
foo(x); foo(x);
return y[0]; return y[0];
} }
@ -300,6 +301,7 @@ bar(undefined); // ok
function foo(x?: number) { function foo(x?: number) {
} }
foo(undefined); foo(undefined);
// ok // ok
function bar(x = \"bar\"): string { function bar(x = \"bar\"): string {
return x; return x;
@ -333,6 +335,7 @@ foo();
// OK // OK
foo(123), // OK foo(123), // OK
foo(123, \"hello\"); foo(123, \"hello\");
// OK // OK
foo(true); foo(true);
// ERROR boolean ~> number // ERROR boolean ~> number

View File

@ -14,6 +14,7 @@ bar({foo: \"\"});
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var x: {} = { foo: 0 }; var x: {} = { foo: 0 };
var y: { foo?: string } = x; var y: { foo?: string } = x;
// OK in TypeScript, not OK in Flow // OK in TypeScript, not OK in Flow
var z: string = y.foo || \"\"; var z: string = y.foo || \"\";
@ -21,6 +22,7 @@ var o = {};
y = o; y = o;
// OK; we know that narrowing could not have happened // OK; we know that narrowing could not have happened
o.foo = 0; o.foo = 0;
// future widening is constrained // future widening is constrained
function bar(config: { foo?: number }) { function bar(config: { foo?: number }) {
} }
@ -48,15 +50,18 @@ var a: { foo?: string } = {};
a.foo = undefined; a.foo = undefined;
// This is not an error // This is not an error
a.foo = null; a.foo = null;
// But this is an error // But this is an error
var b: { foo?: ?string } = {}; var b: { foo?: ?string } = {};
b.foo = undefined; b.foo = undefined;
// This is fine // This is fine
b.foo = null; b.foo = null;
// Also fine // Also fine
var c: { foo?: string } = { foo: undefined }; var c: { foo?: string } = { foo: undefined };
// This is not an error // This is not an error
var d: { foo?: string } = { foo: null }; var d: { foo?: string } = { foo: null };
// But this is an error // But this is an error
var e: { foo?: ?string } = { foo: undefined }; var e: { foo?: ?string } = { foo: undefined };
// This is fine // This is fine

View File

@ -76,12 +76,14 @@ a.foo(0);
a.foo(\"hey\"); a.foo(\"hey\");
// ok // ok
a.foo(true); a.foo(true);
// error, function cannot be called on intersection type // error, function cannot be called on intersection type
a.bar({ a: 0 }); a.bar({ a: 0 });
// ok // ok
a.bar({ a: \"hey\" }); a.bar({ a: \"hey\" });
// ok // ok
a.bar({ a: true }); a.bar({ a: true });
// error, function cannot be called on intersection type // error, function cannot be called on intersection type
declare var x: { a: boolean } & { b: string }; declare var x: { a: boolean } & { b: string };
@ -168,6 +170,7 @@ declare function f(x: string): void;
declare function f(x: number): void; declare function f(x: number): void;
declare var x_f: string | number; declare var x_f: string | number;
f(x_f); f(x_f);
// ok // ok
// maybe // maybe
declare function g(x: null): void; declare function g(x: null): void;
@ -175,6 +178,7 @@ declare function g(x: void): void;
declare function g(x: string): void; declare function g(x: string): void;
declare var x_g: ?string; declare var x_g: ?string;
g(x_g); g(x_g);
// ok // ok
// optional // optional
declare function h(x: void): void; declare function h(x: void): void;

View File

@ -21,6 +21,7 @@ var C = require(\"./ParseError\"); // Flow file
var A = require(\"Foo\"); var A = require(\"Foo\");
// non-Flow file @providesModule Foo // non-Flow file @providesModule Foo
var B = require(\"./NoProvides\"); var B = require(\"./NoProvides\");
// non-Flow file // non-Flow file
var C = require(\"./ParseError\"); // Flow file var C = require(\"./ParseError\"); // Flow file
" "

View File

@ -18,6 +18,7 @@ var B = require(\"./ParseError\"); // Flow file
// non-flow files should not give parse errors // non-flow files should not give parse errors
var A = require(\"./Imported\"); var A = require(\"./Imported\");
// non-Flow file @providesModule Foo // non-Flow file @providesModule Foo
var B = require(\"./ParseError\"); // Flow file var B = require(\"./ParseError\"); // Flow file
" "

View File

@ -15,6 +15,7 @@ class A<X> {}
new A(); new A();
// OK, implicitly inferred type args // OK, implicitly inferred type args
class B extends A {} class B extends A {}
// OK, same as above // OK, same as above
function foo(b): A<any> { function foo(b): A<any> {
// ok but unsafe, caller may assume any type arg // ok but unsafe, caller may assume any type arg

View File

@ -57,6 +57,7 @@ Promise.all([
(b: boolean); (b: boolean);
// Error: number ~> boolean // Error: number ~> boolean
(c: string); (c: string);
// Error: boolean ~> string // Error: boolean ~> string
// array element type is (string | number | boolean) // array element type is (string | number | boolean)
xs.forEach(x => { xs.forEach(x => {
@ -66,9 +67,11 @@ Promise.all([
// First argument is required // First argument is required
Promise.all(); Promise.all();
// Error: expected array instead of undefined (too few arguments) // Error: expected array instead of undefined (too few arguments)
// Mis-typed arg // Mis-typed arg
Promise.all(0); Promise.all(0);
// Error: expected array instead of number // Error: expected array instead of number
// Promise.all is a function // Promise.all is a function
(Promise.all: Function); (Promise.all: Function);
@ -694,6 +697,7 @@ exports[`test resolve_void.js 1`] = `
// @flow // @flow
(Promise.resolve(): Promise<number>); (Promise.resolve(): Promise<number>);
// error // error
(Promise.resolve(undefined): Promise<number>); // error (Promise.resolve(undefined): Promise<number>); // error
" "

View File

@ -22,11 +22,13 @@ function F(props: { foo: string }) {
<F foo={0} />; <F foo={0} />;
/* error: number ~> string*/ /* error: number ~> string*/
<F foo=\"\" />; <F foo=\"\" />;
// ok // ok
// props subtyping is property-wise covariant // props subtyping is property-wise covariant
function G(props: { foo: string | numner }) { function G(props: { foo: string | numner }) {
} }
<G foo=\"\" />; <G foo=\"\" />;
// ok // ok
var Z = 0; var Z = 0;
<Z />; // error, expected React component <Z />; // error, expected React component

View File

@ -92,11 +92,14 @@ pstar = (new P: P<P<number>>); // OK
class P<X> { class P<X> {
x: X; x: X;
} }
// this is like Promise // this is like Promise
type Pstar<X> = X | Pstar<P<X>>; type Pstar<X> = X | Pstar<P<X>>;
// this is like Promise* // this is like Promise*
var p: P<number> = new P(); var p: P<number> = new P();
(p.x: string); (p.x: string);
// error // error
var pstar: Pstar<number> = 0; var pstar: Pstar<number> = 0;
// OK // OK
@ -106,6 +109,7 @@ var pstar: Pstar<number> = 0;
pstar = p; pstar = p;
// OK // OK
(pstar.x: string); (pstar.x: string);
// error // error
pstar = (new P(): P<P<number>>); pstar = (new P(): P<P<number>>);
// OK // OK

View File

@ -36,6 +36,7 @@ o1.foo;
o1.qux; o1.qux;
// error: qux not found // error: qux not found
o1.toString(); o1.toString();
// ok // ok
type R = { foo: any, bar: any }; type R = { foo: any, bar: any };
type Key2 = $Keys<R>; type Key2 = $Keys<R>;
@ -45,6 +46,7 @@ var o2: { [key: Key2]: number } = { foo: 0 };
o2.bar; o2.bar;
// OK to access bar // OK to access bar
o2.qux; o2.qux;
// error: qux not found // error: qux not found
class C<X> { class C<X> {
x: $Subtype<{ [key: $Keys<X>]: any }>; // object with larger key set than X\'s x: $Subtype<{ [key: $Keys<X>]: any }>; // object with larger key set than X\'s

View File

@ -2213,7 +2213,6 @@ function corge(text: string | number | Array<string>): string {
// should only error for string since Array was filtered out. // should only error for string since Array was filtered out.
\"number\": \"number\":
return text++ + \"\"; return text++ + \"\";
default: default:
return \"wat\"; return \"wat\";
} }

View File

@ -157,6 +157,7 @@ require(\"./D\");
var E = require(\"./E\"); var E = require(\"./E\");
var e_1: number = E.numberValue; var e_1: number = E.numberValue;
E.stringValue; E.stringValue;
// Error: The E exports obj has no \'stringValue\' property // Error: The E exports obj has no \'stringValue\' property
// We require that the param passed to require() be a string literal to support // We require that the param passed to require() be a string literal to support
// guaranteed static extraction // guaranteed static extraction
@ -166,6 +167,7 @@ require(a);
require(\`./E\`); require(\`./E\`);
// template literals are ok... // template literals are ok...
require(\`\${\"./E\"}\`); require(\`\${\"./E\"}\`);
// error: but only if they have no expressions // error: but only if they have no expressions
// require.call is allowed but circumverts Flow\'s static analysis // require.call is allowed but circumverts Flow\'s static analysis
require.call(null, \"DoesNotExist\"); require.call(null, \"DoesNotExist\");

View File

@ -72,6 +72,7 @@ requireLazy([ \"A\", \"B\" ], function(A, B) {
var num2: number = A.stringValueA; var num2: number = A.stringValueA;
// Error: string ~> number // Error: string ~> number
var str2: string = A.numberValueA; var str2: string = A.numberValueA;
// Error: number ~> string // Error: number ~> string
var num3: number = B.numberValueB; var num3: number = B.numberValueB;
var str3: string = B.stringValueB; var str3: string = B.stringValueB;

View File

@ -16,15 +16,18 @@ function Foo() {
return {}; return {};
} }
var foo: number = new Foo(); var foo: number = new Foo();
// error (returns object literal above) // error (returns object literal above)
function Bar() { function Bar() {
return 0; return 0;
} }
var bar: number = new Bar(); var bar: number = new Bar();
// error (returns new object) // error (returns new object)
function Qux() { function Qux() {
} }
var qux: number = new Qux(); var qux: number = new Qux();
// error (returns new object) // error (returns new object)
class A {} class A {}
function B() { function B() {
@ -55,8 +58,10 @@ declare class D {
var d = new D(); var d = new D();
d.x = \"\"; d.x = \"\";
// error, string ~/~ number (but property x is found) // 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 // error, new D is an object, D not in proto chain
module.exports = D; module.exports = D;
" "

View File

@ -60,6 +60,7 @@ Foo.prototype = {
}; };
var export_o: { x: any } = o; var export_o: { x: any } = o;
// awkward type cast // awkward type cast
module.exports = export_o; module.exports = export_o;
" "

View File

@ -21,21 +21,27 @@ var o7: { x: number; y?: string; } = ({ x: 0, y: 0 }: { x: number; [_:any]:numbe
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var o1 = { x: 0 }; var o1 = { x: 0 };
var s1: string = o1.y; var s1: string = o1.y;
// error // error
var o2: { x: number, y?: string } = { x: 0 }; var o2: { x: number, y?: string } = { x: 0 };
var s2: string = o2.y || \"\"; var s2: string = o2.y || \"\";
// ok // ok
var o3: { x: number, y?: string } = ({ x: 0, y: 0 }: { x: number }); var o3: { x: number, y?: string } = ({ x: 0, y: 0 }: { x: number });
var s3: string = o3.y || \"\"; var s3: string = o3.y || \"\";
// error // error
var o4: { x: number, y?: string } = ({ x: 0 }: { [_: any]: any, x: number }); var o4: { x: number, y?: string } = ({ x: 0 }: { [_: any]: any, x: number });
var s4: string = o4.y || \"\"; var s4: string = o4.y || \"\";
// ok // ok
var o5 = { x: 0, ...{} }; var o5 = { x: 0, ...{} };
var s5: string = o5.y; var s5: string = o5.y;
// ok (spreads make object types extensible) // ok (spreads make object types extensible)
var o6: { [_: any]: any, x: number } = { x: 0 }; var o6: { [_: any]: any, x: number } = { x: 0 };
var s6: string = o6.y; var s6: string = o6.y;
// ok (indexers make object types extensible) // ok (indexers make object types extensible)
var o7: { x: number, y?: string } = ({ x: 0, y: 0 }: { var o7: { x: number, y?: string } = ({ x: 0, y: 0 }: {
[_: any]: number, [_: any]: number,

View File

@ -28,7 +28,6 @@ for (var i = 0; i < 10; ++i) {
} else { } else {
a[i] = \"\"; a[i] = \"\";
} }
} }
// \`i\` never gets a lower bound, so the array access is stalled until the // \`i\` never gets a lower bound, so the array access is stalled until the
@ -71,7 +70,6 @@ for (var i = 0; i < 10; ++i) {
} else { } else {
a[i] = \"\"; a[i] = \"\";
} }
} }
function foo(i: number): string { function foo(i: number): string {

View File

@ -45,6 +45,7 @@ function veryOptimistic(isThisAwesome: true): boolean {
var x: boolean = veryOptimistic(true); var x: boolean = veryOptimistic(true);
var y: boolean = veryOptimistic(false); var y: boolean = veryOptimistic(false);
// error // error
function veryPessimistic(isThisAwesome: true): boolean { function veryPessimistic(isThisAwesome: true): boolean {
return !isThisAwesome; // test bool conversion return !isThisAwesome; // test bool conversion
@ -52,6 +53,7 @@ function veryPessimistic(isThisAwesome: true): boolean {
var x: boolean = veryPessimistic(true); var x: boolean = veryPessimistic(true);
var y: boolean = veryPessimistic(false); var y: boolean = veryPessimistic(false);
// error // error
type MyOwnBooleanLOL = true | false; type MyOwnBooleanLOL = true | false;
@ -66,6 +68,7 @@ function bar(x: MyOwnBooleanLOL): false {
bar(true); bar(true);
bar(false); bar(false);
bar(1); bar(1);
// error // error
function alwaysFalsy(x: boolean): false { function alwaysFalsy(x: boolean): false {
if (x) { if (x) {
@ -110,6 +113,7 @@ function highlander(howMany: 1): number {
highlander(1); highlander(1);
highlander(2); highlander(2);
// error // error
type Foo = 1 | 2; type Foo = 1 | 2;
@ -120,6 +124,7 @@ function bar(num: Foo): number {
bar(1); bar(1);
bar(2); bar(2);
bar(3); bar(3);
// error // error
type ComparatorResult = -1 | 0 | 1; type ComparatorResult = -1 | 0 | 1;
function sort(fn: (x: any, y: any) => ComparatorResult) { function sort(fn: (x: any, y: any) => ComparatorResult) {

View File

@ -138,6 +138,7 @@ interface HasOptional { a: string, b?: number }
var test1: HasOptional = { a: \"hello\" }; var test1: HasOptional = { a: \"hello\" };
var test2: HasOptional = {}; var test2: HasOptional = {};
// Error: missing property a // Error: missing property a
var test3: HasOptional = { a: \"hello\", b: true }; // Error: boolean ~> number var test3: HasOptional = { a: \"hello\", b: true }; // Error: boolean ~> number
" "

View File

@ -26,9 +26,11 @@ var test6: string = 123;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// $FlowFixMe // $FlowFixMe
var test1: string = 123; var test1: string = 123;
// This error should be suppressed // This error should be suppressed
// $FlowIssue // $FlowIssue
var test2: string = 123; var test2: string = 123;
// This error should be suppressed // This error should be suppressed
function getNum() { function getNum() {
return 123; return 123;
@ -36,12 +38,15 @@ function getNum() {
// $FlowFixMe This was the second loc in the error // $FlowFixMe This was the second loc in the error
var test3: string = getNum(); var test3: string = getNum();
// This error should be suppressed // This error should be suppressed
// $FlowFixMe Error unused suppression // $FlowFixMe Error unused suppression
var test4: string = 123; var test4: string = 123;
// This error is NOT suppressed // This error is NOT suppressed
// $FlowFixMe Indentation shouldn\'t matter // $FlowFixMe Indentation shouldn\'t matter
var test5: string = 123; var test5: string = 123;
// This error should be suppressed // This error should be suppressed
/* /*
* $FlowNewLine * $FlowNewLine

View File

@ -193,6 +193,7 @@ function foo(x: mixed): string {
(a: string); (a: string);
// error, string | number ~/> string // error, string | number ~/> string
(a: number); (a: number);
// error, string | number ~/> number // error, string | number ~/> number
// b is now number // b is now number
(b: number); (b: number);
@ -218,11 +219,13 @@ function baz(x: mixed): number {
(a: string); (a: string);
// error, string | number ~/> string // error, string | number ~/> string
(a: number); (a: number);
// error, string | number ~/> number // error, string | number ~/> number
// b is now string | number // b is now string | number
(b: string); (b: string);
// error, string | number ~/> string // error, string | number ~/> string
(b: number); (b: number);
// error, string | number ~/> number // error, string | number ~/> number
return a + b; // error, string ~/> number return a + b; // error, string ~/> number
} }

View File

@ -111,6 +111,7 @@ let tests = [
function(x: $Tainted<string>) { function(x: $Tainted<string>) {
let obj: Object = {}; let obj: Object = {};
obj.foo(x); obj.foo(x);
// error, taint ~> any // error, taint ~> any
let foo = obj.foo; let foo = obj.foo;
foo(x); // error, taint ~> any foo(x); // error, taint ~> any

View File

@ -70,10 +70,12 @@ let tests = [
(\`bar\`: \"bar\"); (\`bar\`: \"bar\");
// ok // ok
(\`baz\`: number); (\`baz\`: number);
// error // error
\`foo \${123} bar\`; \`foo \${123} bar\`;
// ok, number can be appended to string // ok, number can be appended to string
\`foo \${{ bar: 123 }} baz\`; \`foo \${{ bar: 123 }} baz\`;
// error, object can\'t be appended // error, object can\'t be appended
let tests = [ let tests = [
function(x: string) { function(x: string) {

View File

@ -76,11 +76,13 @@ var o1 = new F();
// sets o1.x to 0 // sets o1.x to 0
o1.x = \"\"; o1.x = \"\";
foo(o1.x); foo(o1.x);
// ok by definite assignment // ok by definite assignment
var o2 = new F(); var o2 = new F();
o1.y = 0; o1.y = 0;
o2.y = \"\"; o2.y = \"\";
foo(o2.y); foo(o2.y);
// setting o1.y to 0 has no effect on o2.y // setting o1.y to 0 has no effect on o2.y
var o3 = new F(); var o3 = new F();
o3.m(); o3.m();
@ -89,6 +91,7 @@ o3.y = \"\";
foo(o3.y); foo(o3.y);
// ok by definite assignment // ok by definite assignment
foo(o2.y); foo(o2.y);
// setting o3.y to 0 has no effect on o2.y // setting o3.y to 0 has no effect on o2.y
/* /*
* this bindings: * this bindings:
@ -106,6 +109,7 @@ var f1_3 = f1.bind({ x: \"\" })();
// error, string -> number // error, string -> number
// TODO make this error blame the call site, rather than the function body // TODO make this error blame the call site, rather than the function body
var f1_4 = f1(); var f1_4 = f1();
// error, (global object).x // error, (global object).x
/* arrow functions bind this at point of definition */ /* arrow functions bind this at point of definition */
/* top level arrow functions bind this to global object */ /* top level arrow functions bind this to global object */
@ -114,6 +118,7 @@ var a1 = () => {
}; };
var ax = a1(); var ax = a1();
// error, (this:mixed).x // error, (this:mixed).x
/* nested arrows bind enclosing this (which may itself rebind) */ /* nested arrows bind enclosing this (which may itself rebind) */
function f2(): number { function f2(): number {
@ -131,6 +136,7 @@ var f2_3 = f2.bind({ x: \"\" })();
// error, string -> number // error, string -> number
// TODO make this error blame the call site, rather than the function body // TODO make this error blame the call site, rather than the function body
var f2_4 = f2(); var f2_4 = f2();
// error, (global object).x // error, (global object).x
(this: void); (this: void);
@ -182,6 +188,7 @@ var f = c.foo();
var i = f(); var i = f();
// OK // OK
(i: C); (i: C);
// OK // OK
class D extends C {} class D extends C {}
var d = new D(); var d = new D();
@ -189,6 +196,7 @@ var g = d.foo();
var j = g(); var j = g();
// OK // OK
(j: D); (j: D);
// error, since return type of bar is C, not the type of \`this\` // error, since return type of bar is C, not the type of \`this\`
class E { class E {
foo(x: number) { foo(x: number) {

View File

@ -87,6 +87,7 @@ class D extends C {}
var d = new D(); var d = new D();
(d: C).next = new C(); (d: C).next = new C();
(d.next: D); (d.next: D);
// sneaky // sneaky
class A { class A {
foo<X: this>(that: X) { foo<X: this>(that: X) {
@ -249,6 +250,7 @@ class B1 extends A1 {
} }
(new B1().bar(): B1); (new B1().bar(): B1);
// OK // OK
class B3<X> extends A3<X> { class B3<X> extends A3<X> {
foo(): B3<X> { foo(): B3<X> {
@ -259,6 +261,7 @@ class B3<X> extends A3<X> {
(new B3().bar(): B3<*>); (new B3().bar(): B3<*>);
// OK // OK
(new B3().qux(0): string); (new B3().qux(0): string);
// error // error
(new B3().bar(): A2<*>); (new B3().bar(): A2<*>);
// OK // OK
@ -377,6 +380,7 @@ class A {
} }
} }
class B extends A {} class B extends A {}
// inherits statics method too, with \`this\` bound to the class // inherits statics method too, with \`this\` bound to the class
(A.make(): A); (A.make(): A);
// OK // OK
@ -488,6 +492,7 @@ class Override extends Base {
qux() { qux() {
return this; return this;
} }
// OK, too // OK, too
bar() { bar() {
return new Override(); return new Override();
@ -540,6 +545,7 @@ class Override2 extends Base2 {
qux(): this { qux(): this {
return this; return this;
} }
// OK, too // OK, too
bar(): Override2 { bar(): Override2 {
return new Override2(); return new Override2();
@ -566,6 +572,7 @@ class InheritOverride2 extends Override2 {}
((new Override2(): Base2).foo(): Base2); ((new Override2(): Base2).foo(): Base2);
(new InheritOverride2().bar_caller(): InheritOverride2); (new InheritOverride2().bar_caller(): InheritOverride2);
// exploits error above // exploits error above
(new Override2(): Base2).corge(new Base2()); // exploits error above (new Override2(): Base2).corge(new Base2()); // exploits error above
" "

View File

@ -34,6 +34,7 @@ exports[`test optional.js 1`] = `
([ 0, undefined ]: [number, ?string]); ([ 0, undefined ]: [number, ?string]);
// Ok, correct arity // Ok, correct arity
([ 0 ]: [number, ?string]); ([ 0 ]: [number, ?string]);
// Error, arity is enforced // Error, arity is enforced
([]: [?number, string]); // error, since second element is not marked optional ([]: [?number, string]); // error, since second element is not marked optional
" "

View File

@ -94,6 +94,7 @@ class MyClass<T> {
} }
var c: MyClass = new MyClass(0); var c: MyClass = new MyClass(0);
// no error // no error
// no arity error in type annotation using polymorphic class with defaulting // no arity error in type annotation using polymorphic class with defaulting
class MyClass2<T, U=string> { class MyClass2<T, U=string> {
@ -106,14 +107,17 @@ class MyClass2<T, U=string> {
} }
var c2: MyClass2 = new MyClass2(0, \"\"); var c2: MyClass2 = new MyClass2(0, \"\");
// no error // no error
// no arity error in type annotation using polymorphic type alias // no arity error in type annotation using polymorphic type alias
type MyObject<T> = { x: T }; type MyObject<T> = { x: T };
var o: MyObject = { x: 0 }; var o: MyObject = { x: 0 };
// no error // no error
// arity error in type alias rhs // arity error in type alias rhs
type MySubobject = { y: number } & MyObject; type MySubobject = { y: number } & MyObject;
// no error // no error
// arity error in interface extends // arity error in interface extends
interface MyInterface<T> { x: T } interface MyInterface<T> { x: T }

View File

@ -92,6 +92,7 @@ class MyClass<T> {
} }
var c: MyClass = new MyClass(0); var c: MyClass = new MyClass(0);
// error, missing argument list (1) // error, missing argument list (1)
// arity error in type annotation using polymorphic class with defaulting // arity error in type annotation using polymorphic class with defaulting
class MyClass2<T, U=string> { class MyClass2<T, U=string> {
@ -104,14 +105,17 @@ class MyClass2<T, U=string> {
} }
var c2: MyClass2 = new MyClass2(0, \"\"); var c2: MyClass2 = new MyClass2(0, \"\");
// error, missing argument list (1-2) // error, missing argument list (1-2)
// arity error in type annotation using polymorphic type alias // arity error in type annotation using polymorphic type alias
type MyObject<T> = { x: T }; type MyObject<T> = { x: T };
var o: MyObject = { x: 0 }; var o: MyObject = { x: 0 };
// error, missing argument list // error, missing argument list
// arity error in type alias rhs // arity error in type alias rhs
type MySubobject = { y: number } & MyObject; type MySubobject = { y: number } & MyObject;
// error, missing argument list // error, missing argument list
// arity error in interface extends // arity error in interface extends
interface MyInterface<T> { x: T } interface MyInterface<T> { x: T }

View File

@ -88,8 +88,10 @@ var b_star: B<*> = new B(123);
(b_void.p: boolean); (b_void.p: boolean);
// Error void ~> boolean // Error void ~> boolean
(b_default.p: boolean); (b_default.p: boolean);
// Error string ~> boolean // Error string ~> boolean
(b_star.p: boolean); (b_star.p: boolean);
// Error number ~> boolean // Error number ~> boolean
class C<T: ?string=string> extends A<T> {} class C<T: ?string=string> extends A<T> {}
@ -104,6 +106,7 @@ var c_star: C<*> = new C(\"hello\");
(c_default.p: boolean); (c_default.p: boolean);
// Error string ~> boolean // Error string ~> boolean
(c_star.p: boolean); (c_star.p: boolean);
// Error string ~> boolean // Error string ~> boolean
class D<S, T=string> extends A<T> {} class D<S, T=string> extends A<T> {}
var d_number: D<mixed, number> = new D(123); var d_number: D<mixed, number> = new D(123);
@ -114,6 +117,7 @@ var d_too_few_args: D<> = new D(\"hello\");
var d_too_many: D<mixed, string, string> = new D(\"hello\"); var d_too_many: D<mixed, string, string> = new D(\"hello\");
// Error too many tparams // Error too many tparams
var d_star: D<*> = new D(10); var d_star: D<*> = new D(10);
// error, number ~> string // error, number ~> string
(d_number.p: boolean); (d_number.p: boolean);
// Error number ~> boolean // Error number ~> boolean
@ -122,18 +126,22 @@ var d_star: D<*> = new D(10);
(d_default.p: boolean); (d_default.p: boolean);
// Error string ~> boolean // Error string ~> boolean
(d_star.p: boolean); (d_star.p: boolean);
// Error number ~> boolean // Error number ~> boolean
class E<S: string, T: number=S> {} class E<S: string, T: number=S> {}
// Error: string ~> number // Error: string ~> number
class F<S: string, T: S=number> {} class F<S: string, T: S=number> {}
// Error: number ~> string // Error: number ~> string
class G<S: string, T=S> extends A<T> {} class G<S: string, T=S> extends A<T> {}
var g_default: G<string> = new G(\"hello\"); var g_default: G<string> = new G(\"hello\");
(g_default.p: boolean); (g_default.p: boolean);
// Error string ~> boolean // Error string ~> boolean
class H<S=T, T=string> {} class H<S=T, T=string> {}
// Error - can\'t refer to T before it\'s defined // Error - can\'t refer to T before it\'s defined
class I<T: ?string=*> extends A<T> {} class I<T: ?string=*> extends A<T> {}

View File

@ -155,6 +155,7 @@ g.m(0);
g.m(true); g.m(true);
// err, bool ~> number|string // err, bool ~> number|string
(g.m(\"\"): G<number>); (g.m(\"\"): G<number>);
// err, string ~> number // err, string ~> number
// Shadow bounds incompatible with parent // Shadow bounds incompatible with parent
class H<T> { class H<T> {

View File

@ -144,6 +144,7 @@ var c: typeof MyClass2 = new MyClass2();
var numValue: number = 42; var numValue: number = 42;
var d: typeof numValue = 100; var d: typeof numValue = 100;
var e: typeof numValue = \"asdf\"; var e: typeof numValue = \"asdf\";
// Error: string ~> number // Error: string ~> number
///////////////////////////////// /////////////////////////////////
// == typeof <<type-alias>> == // // == typeof <<type-alias>> == //
@ -155,6 +156,7 @@ type numberAlias = number;
// is suboptimal - just \'cannot resolve name\'. TODO. // is suboptimal - just \'cannot resolve name\'. TODO.
// //
var f: typeof numberAlias = 42; var f: typeof numberAlias = 42;
// Error: \'typeof <<type-alias>>\' makes no sense... // Error: \'typeof <<type-alias>>\' makes no sense...
/** /**
* Use of a non-class/non-function value in type annotation. * Use of a non-class/non-function value in type annotation.

View File

@ -38,17 +38,20 @@ var x3: string = buffer3.INSPECT_MAX_BYTES; // error, module not found
// //
var buffer = require(\"buffer\"); var buffer = require(\"buffer\");
var b: boolean = buffer.INSPECT_MAX_BYTES; var b: boolean = buffer.INSPECT_MAX_BYTES;
// error, number ~/> boolean // error, number ~/> boolean
// node_modules/crypto/index.js is checked, // node_modules/crypto/index.js is checked,
// so we should pick up its boolean redefinition of DEFAULT_ENCODING // so we should pick up its boolean redefinition of DEFAULT_ENCODING
// //
var crypto = require(\"crypto\"); var crypto = require(\"crypto\");
var b: boolean = crypto.DEFAULT_ENCODING; var b: boolean = crypto.DEFAULT_ENCODING;
// no error, we\'ve overridden // no error, we\'ve overridden
// names that are explicit paths shouldn\'t fall back to lib defs // names that are explicit paths shouldn\'t fall back to lib defs
// //
var buffer2 = require(\"./buffer\"); var buffer2 = require(\"./buffer\");
var x2: string = buffer2.INSPECT_MAX_BYTES; var x2: string = buffer2.INSPECT_MAX_BYTES;
// error, module not found // error, module not found
var buffer3 = require(\"./buffer.js\"); var buffer3 = require(\"./buffer.js\");
var x3: string = buffer3.INSPECT_MAX_BYTES; // error, module not found var x3: string = buffer3.INSPECT_MAX_BYTES; // error, module not found

View File

@ -15,6 +15,7 @@ foo();
function doSomethingAsync(): Promise<void> { function doSomethingAsync(): Promise<void> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve(); resolve();
// OK to leave out arg, same as resolve(undefined) // OK to leave out arg, same as resolve(undefined)
var anotherVoidPromise: Promise<void> = Promise.resolve(); var anotherVoidPromise: Promise<void> = Promise.resolve();
resolve(anotherVoidPromise); resolve(anotherVoidPromise);
@ -96,6 +97,7 @@ let tests = [
var id; var id;
var name = id ? \"John\" : undefined; var name = id ? \"John\" : undefined;
(name: boolean); (name: boolean);
// error, string or void // error, string or void
const bar = [ undefined, \"bar\" ]; const bar = [ undefined, \"bar\" ];
(bar[x]: boolean); // error, string or void (bar[x]: boolean); // error, string or void
@ -103,6 +105,7 @@ let tests = [
function(x: number) { function(x: number) {
var undefined = \"foo\"; var undefined = \"foo\";
(undefined: string); (undefined: string);
// ok // ok
var x; var x;
if (x !== undefined) { if (x !== undefined) {

Some files were not shown because too many files have changed in this diff Show More