Skip to content

type intersection not working #9237

Open
@trusktr

Description

Flow version: 0.256

I'm trying to write a type definition for a class-factory mixins. If it could be improved,

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:

Flow Try example 1

If you swap the {...} with T, then the opposite set of properties are ignored:

Flow Try example 2

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions