// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`annot.js 1`] = ` class A { } new A; // OK, implicitly inferred type args class B extends A { } // OK, same as above function foo(b): A { // ok but unsafe, caller may assume any type arg return b ? (new A: A): (new A: A); } function bar(): A<*> { // error, * can't be {} and {x: string} at the same time return (new A: A<{}>) || (new A: A<{x: string}>); } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class A {} new A(); // OK, implicitly inferred type args class B extends A {} // OK, same as above function foo(b): A { // ok but unsafe, caller may assume any type arg return b ? (new A(): A) : (new A(): A); } function bar(): A<*> { // error, * can't be {} and {x: string} at the same time return (new A(): A<{}>) || (new A(): A<{ x: string }>); } `; exports[`implicit_bounded_instantiation.js 1`] = ` // @flow class Base {} class Middle extends Base {} class Child extends Middle {} class C { meth(a: T): T { return a; } } // T is implicitly (bounded by) Middle in constructor call if not provided. // Explicit type arg is required in annotation - here a wildcard captures it. var a: C<*> = new C(); a.meth(new Middle()); a.meth(new Child()); a.meth(42); // Error: number ~> Middle a.meth(new Base()); // Error: Base ~> Middle ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow class Base {} class Middle extends Base {} class Child extends Middle {} class C { meth(a: T): T { return a; } } // T is implicitly (bounded by) Middle in constructor call if not provided. // Explicit type arg is required in annotation - here a wildcard captures it. var a: C<*> = new C(); a.meth(new Middle()); a.meth(new Child()); a.meth(42); // Error: number ~> Middle a.meth(new Base()); // Error: Base ~> Middle `; exports[`issue-1029.js 1`] = ` // @flow // naive unification causes combinatorial explosion here, // effectively hangs declare type Box = { map1(f: (x: T) => U): Box; map2(f: (x: T) => U): Box; map3(f: (x: T) => U): Box; map4(f: (x: T) => U): Box; map5(f: (x: T) => U): Box; } declare var bool: Box; declare function unbox(box: Box): A unbox(bool); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow // naive unification causes combinatorial explosion here, // effectively hangs declare type Box = { map1(f: (x: T) => U): Box, map2(f: (x: T) => U): Box, map3(f: (x: T) => U): Box, map4(f: (x: T) => U): Box, map5(f: (x: T) => U): Box }; declare var bool: Box; declare function unbox(box: Box): A; unbox(bool); `; exports[`poly.js 1`] = ` class Foo { x:T; constructor(x:T) { this.x = x; } } function bar(foo:Foo,y:S):Foo { return new Foo(y); } var P = { bar: bar } declare var Q: { bar(foo:Foo,y:S):Foo; } var foo = new Foo(0); var x:string = foo.x; var z:Foo = Q.bar(foo,""); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class Foo { x: T; constructor(x: T) { this.x = x; } } function bar(foo: Foo, y: S): Foo { return new Foo(y); } var P = { bar: bar }; declare var Q: { bar(foo: Foo, y: S): Foo }; var foo = new Foo(0); var x: string = foo.x; var z: Foo = Q.bar(foo, ""); `; exports[`test.js 1`] = ` class C { foo(x: X): X { return x; } foo_(x: X): number { return x; } bar(x: X): X { return x; } qux(x: number): number { return x; } } class D extends C { foo(x: number): number { return x; } // error (specialization, see below) foo_(x: number): number { return x; } // OK, but only because the overridden foo accepts no more than number and returns exactly number bar(x: X): X { return x; } // OK qux(x: X): X { return x; } // OK (generalization) } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class C { foo(x: X): X { return x; } foo_(x: X): number { return x; } bar(x: X): X { return x; } qux(x: number): number { return x; } } class D extends C { foo(x: number): number { return x; } // error (specialization, see below) foo_(x: number): number { return x; } // OK, but only because the overridden foo accepts no more than number and returns exactly number bar(x: X): X { return x; } // OK qux(x: X): X { return x; } // OK (generalization) } `;