Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type intersection not working #9237

Open
trusktr opened this issue Dec 8, 2024 · 0 comments
Open

type intersection not working #9237

trusktr opened this issue Dec 8, 2024 · 0 comments

Comments

@trusktr
Copy link
Contributor

trusktr commented Dec 8, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant