61 lines
1.4 KiB
Plaintext
61 lines
1.4 KiB
Plaintext
exports[`test test.js 1`] = `
|
|
"class A { }
|
|
function foo(x: Class<A>): A {
|
|
return new x(); // OK
|
|
}
|
|
|
|
class B {
|
|
constructor(_: any) { }
|
|
}
|
|
function bar(x: Class<B>): B {
|
|
return new x(); // error (too few args)
|
|
}
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
class A {}
|
|
function foo(x: Class<A>): A {
|
|
return new x(); // OK
|
|
}
|
|
|
|
class B {
|
|
constructor(_: any) {
|
|
}
|
|
}
|
|
function bar(x: Class<B>): B {
|
|
return new x(); // error (too few args)
|
|
}
|
|
"
|
|
`;
|
|
|
|
exports[`test test2.js 1`] = `
|
|
"// A function to typecheck values against their types. Covariance of Class<.>
|
|
// makes it useless in such a function (when limited to classes and instances),
|
|
// since everything can be trivially satisfied by going to \`mixed\`.
|
|
declare function check<X>(cls: $Type<X>, inst: X): void;
|
|
|
|
class A { }
|
|
class B extends A { }
|
|
class C { }
|
|
|
|
check(B, new A);
|
|
check(A, new B);
|
|
check(C, new A);
|
|
check(C, new B);
|
|
check(B, new C);
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// A function to typecheck values against their types. Covariance of Class<.>
|
|
// makes it useless in such a function (when limited to classes and instances),
|
|
// since everything can be trivially satisfied by going to \`mixed\`.
|
|
declare function check<X>(cls: $Type<X>, inst: X): void;
|
|
|
|
class A {}
|
|
class B extends A {}
|
|
class C {}
|
|
|
|
check(B, new A());
|
|
check(A, new B());
|
|
check(C, new A());
|
|
check(C, new B());
|
|
check(B, new C());
|
|
"
|
|
`;
|