Such as System.global, System.import...
System.import support would really be handy. I don't think there's a proper way to work around this. The best I can come up with is
declare var System: {
import: (module: string) => Promise<Object>;
}
and put up with no type-checking on the use of asynchronously imported modules. Preferably, Flow would know that if I System.import('./foo'), and ./foo.js looks like this:
export default function(a: number): number { return a+1; }
export const inc = 1;
then the return value of that import is
Promise<{
default: (a: number) => number,
inc: number,
}>
In other words, this is more than just a library definition. Flow needs to understand the semantics of System.import.
Any update on this? Think I will just have to ignore System.import in flow for now.
@andykenward is there a spec for this?
this isn't settled yet https://github.com/tc39/proposal-dynamic-import
@bloodyowl I know about this one, but I think that System is pretty much obsolete
@vkurchatkin it seems so, yes
AFAIK no browsers supports it. if it's meant to be used with the SystemJS library, I'd advice to create the definitions in https://github.com/flowtype/flow-typed and wait for an official specification before adding anything in flow/lib
I am using it for webpack 2 code splitting feature. I suppose I could switch to require.ensure.
Thanks for the quick response
There is an open issue for dynamic import, https://github.com/facebook/flow/issues/2968
And global is at stage 3 of the spec proposal process, it would seem like this issue can be closed in favor of others.
I solved it with this declaration:
declare interface System {
static import: (module: string) => Promise<{
default: any,
inc: number,
}>
};
Might help someone! (Note: System.import() is deprecated in stable Webpack 2 and replaced by import(), I haven't started using this yet, however. Will that cause crazy module issues with Flow in the future?)
Will that cause crazy module issues with Flow in the future?)
Most definitely. You code won't even parse until this feature is implemented in Flow. See https://github.com/facebook/flow/issues/2968
Closing since System proposal is abandoned