Flow: Suppressed error with when exist property with any type in class

Created on 25 Feb 2017  路  4Comments  路  Source: facebook/flow

Excuse for confusing title, difficult explain my case in few words.
I'm declare custom class system and everything alright until not appearing property oops: JQuery, which suppress expected error:

declare var JQuery: any;

declare class BEM {
    static decl<P, SP>(block: string, props: P, staticProps?: SP): Class<BEM & P> & SP;
    static blocks: { [name: string]: Class<*> };
    // oops: JQuery; // <- This line suppress an error.
}

var Provider = BEM.decl('provider', {}, {
    foo: function(a: string) {}
});

var p: typeof Provider = BEM.blocks['provider'];
p.foo('');
p.bla(); // <- Expected error "property `bla`. Property not found in."

Experimentally I found that declaration below is not suppress an error:

declare class JQuery {}

But why the first code has the described behavior? Is it bug?
Flow version 0.40.0.

unionintersections bug

Most helpful comment

Here is a minimal test case:

declare var A: any;
declare var y: { a: A } & {};
y.foo;

All 4 comments

If you use oops: typeof JQuery;, it works as intended. You're using a value as a type, which normally throws an error, but doesn't for some reason with any.

Having no error message seems like a bug?

If you use oops: typeof JQuery;, it works as intended.

Thank you for explanation, typeof fixes that behavior.

Having no error message seems like a bug?

Yes, I'm expect error about missing p.bla(). But oops: JQuery; suppressed her.

Having no error message seems like a bug?

Yes, it seems so

Here is a minimal test case:

declare var A: any;
declare var y: { a: A } & {};
y.foo;
Was this page helpful?
0 / 5 - 0 ratings