-
Notifications
You must be signed in to change notification settings - Fork 49
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
Object type spread failing on imported type from other module or libdef (e.g. flow-typed) #106
Comments
Problem identified: I expected the I'll need to get the actual definition instead of what appears to be a raw pointer. |
@brigand I see this marked in code as a |
I think so, yes. cc @mhaas (who wrote this code) |
@mhaas - which test code is best for me to look at for this runtime intersection from a libdef? |
This seems like a strange situation, as I need to alter the imported named type by obtaining the properties only (and in cases that don't use Where I do this manipulation makes sense (when not importing), perhaps someone can shed some light on why we are doing this at That's the only way this could work, is it not? |
This plugin doesn't read other files, so it doesn't know the types exported from other files until runtime. I'd like to keep it this way, but I'm convincible. @thejameskyle is working on a similar plugin that reads other files (not open source yet, afaik). |
Ah, it is open source. https://github.com/thejameskyle/babel-plugin-react-flow-props-to-prop-types |
Any To me this means the usefulness is severely limited. In my case, I created a libdef for In my opinion, we must read these files at transpilation time to be useful. I see the @thejameskyle plugin doesn't have issues enabled. Did that project split off due to the runtime concern? Is there a way to bring these two together for babel-7? |
I saw the commentary on inlining types and solving the react-docgen problem, which is also a problem for me. I'm going to try out that new plugin and see where it leads. |
Can we transpile flow-typed? |
@mhaas we should be able to interpret flow types from |
I agree that Why do we have to process |
|
@rosskevin We can transpile the local libdef just like we handle type exports. On the import side, the |
@rosskevin Can you post your libdef for found? I am still trying to wrap my head around libdefs - I guess the only scenario we need to handle is something like this:
|
I found some interesting discussion here:gajus/flow-runtime#27 They apparently have a tool that preprocesses libdefs and makes them available. |
@mhaas here is a It seems with object type spreads in particular, we really don't have a workaround for imported types, which is a huge problem for me now... |
@rosskevin Thanks! It would seem to me that we need to do two things to handle import types from a libdef:
By the way, you mentioned that imported types do not work for object type spreads. This is only true for imported types from libdef files, correct? |
Correct. We also need to crawl/parse *.js.flow files from node_modules, these are untranspiled source files. |
Just a quick note, I can see that https://github.com/thejameskyle/babel-plugin-react-flow-props-to-prop-types/blob/master/fixtures/imports/code.js is importing types from other files. This does not cover libdefs, but it is cross-module. Source seems to be I've found that plugin structure simpler and easier to follow, but it is far from complete and won't work with my projects. This plugin is much more complete. Perhaps some inspiration from the other and a little refactoring here could get this plugin resolving local imports. |
I've determined that importing from a libdef might be too ambitious near term, but importing cross-module from js source code seems plausible based on the code I found above. I can't dedicate the time at the moment, but if someone wants to give it a shot, I think the code pointers above will get it done. If I have time, I'll get to it. |
babel-plugin-react-flow-props-to-prop-types - work with imports but dosn't work with object spread import type { TodoView } from 'modules/todo/reducers';
type Props = {
...TodoView,
onClick: (id: number) => void,
onEdit: (id: number) => void
}; What to do to make it work? |
@UchihaVeha - that is the exact case for this issue, it does not import the type from another file so it is null and fails. If type |
Any progress here? |
I believe this fails due to the same root cause:
in |
Is there any progress on this issue? |
Any way I can help move this forward? |
I apologize for such a long standing issue. @TSMMark I might be able to work on this on the weekend, but if you have some time, I would very much appreciate a PR that either makes this fail softly or one that actually implements the expected behavior with exact types + spread. |
@brigand I was trying to use this plugin but I couldn't seem to get it to add propTypes to any components for some reason. If I'm able to invest any time in it it's going to have to be trying to resolve that issue – sorry! |
In my built files I'm seeing |
@TSMMark that might happen if you have a type import ( |
babel-7
branch - I'm looking into this.found
is in a local libdef.The text was updated successfully, but these errors were encountered: