Open
Description
Flow version: 0.256
I'm trying to write a type definition for a class-factory mixins. If it could be improved,
- Support for class-factory mixins. #9236 (I wish it was not shot down so quickly)
it would be helpful, but for now I'm trying to explicitly define the return type annotation for a function to make it work.
However I haven't had luck, and very thankful to @panagosg7 for helping me. @panagosg7 thought there may be a bug when we got as far as in the example below:
Expected behavior
The &
operator should successfully join the two types together:
Code:
class A {
aMethod(): number { return 123 }
}
class B extends A {
bMethod(): number { return 123 }
}
declare function ChildTracker<T extends Object>(Base: Class<T>): Class<interface {
constructor(): T & { // <--------------- Here's the intersection
foo(): number;
}
}> & {
bar: string;
};
const Ctor = ChildTracker(B);
const s: string = Ctor.bar as string
const b = new Ctor();
b.aMethod()
b.bMethod()
b.foo() // <------------------ HERE, .foo is missing
Actual behavior
The second type in the T & {...}
seems to be ignored:
If you swap the {...}
with T
, then the opposite set of properties are ignored: