Files
test-repo/tests/flow/constructor/constructor.js
T

22 lines
561 B
JavaScript
Raw Normal View History

2016-12-23 19:31:38 +00:00
class C {
constructor() { }
}
class D {
constructor():number { }
}
2017-04-08 16:52:38 +02:00
// the return type of a constructor overrides the type of the class
declare class Bar<T> {}
declare class Foo<T> {
constructor<U>(iterable: U): Bar<U>;
}
(new Foo('x'): Bar<string>); // ok
(new Foo(123): Bar<string>); // error, number !~> string
// also overrides when it returns a different specialization of the same class
declare class Baz<T> {
constructor<U>(iterable: U): Baz<U>;
}
(new Baz('x'): Baz<string>); // ok
(new Baz(123): Baz<string>); // error, number !~> string