-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Modern:rc.2] Generated fragment flow type info is being lost on import #1689
Comments
Thanks for the easy repro case, I reduced it a bit more and it seems like imported types from untyped modules are different from https://gist.github.com/kassens/70e59033630c3a24af236225bbfc4f21 |
It looks like if you import a type that is not declared in the module you are importing from, it will have an Is there some intention behind adding type imports/annotations to generated files for types that don't actually exist in the published module? A fix for anyone else who hits this issue is to add a flow library definition file for // File .flowconfig
[ignore]
[include]
[libs]
./lib
[options] // File: lib/relay-runtime.js
declare module 'relay-runtime' {
// Public API values
declare var Environment: any;
declare var Network: any;
declare var RecordSource: any;
declare var Store: any;
declare var areEqualSelectors: any;
declare var createFragmentSpecResolver: any;
declare var createOperationSelector: any;
declare var getDataIDsFromObject: any;
declare var getFragment: any;
declare var getOperation: any;
declare var getSelector: any;
declare var getSelectorList: any;
declare var getSelectorsFromObject: any;
declare var getVariablesFromObject: any;
declare var graphql: any;
declare var ConnectionHandler: any;
declare var ViewerHandler: any;
declare var commitLocalUpdate: any;
declare var commitMutation: any;
declare var fetchQuery: any;
declare var isRelayStaticEnvironment: any;
declare var requestSubscription: any;
// Internal types imported in compiler generated files
declare type ConcreteFragment = any;
declare type ConcreteBatch = any;
} |
If I'm reading this issue correctly, does that mean that the flow typing is not working at all at the moment? |
@ekosz Yes and no. The flow type that is generated for the fragment is correct. But there are other flow types that are added to the generated file that do not exist. Flow doesn't appear to be able to deal with these non-existent types in a sensible manner (under certain conditions), and leads to us not being able to import any other types from that module. Therefore, even though the fragment type is correct, when we try to import the fragment type, flow incorrectly thinks it has an If you look at the original code I pasted, the problem lines are these ones: The Flow gets all confused because of this non-existent type. To work around this, we can provide our own library definition file for In the library definition file I pasted above, the relevant lines are these ones:
|
See #1758 for a discussion around resolving this issue. |
Closing in favor of #1758 to keep all the discussion in one place. |
@nirrek thanks for sharing! I also add
I wish
that would be amazing! |
When using an imported flow type for a fragment that was generated by
relay-compiler
the type information seems to be getting lost. Usingflow type-at-pos
will report the type as(unknown)
. This is when using[email protected]
and[email protected]
.There's a simplified repo here demonstrating the issue: https://github.com/nirrek/relay-modern-flow-types. I've also inlined the relevant code in the issue below as there's not much to it.
I'm not familiar enough with the inner working of flow to figure out what's going wrong here. There are two different ways I found that allow the
index_user
type to propagate properly though, so maybe that will offer some clues as to what's going on:export default fragment
instead ofmodule.exports = fragment
ConcreteFragement
type annotation onfragment
.The text was updated successfully, but these errors were encountered: