-
-
Notifications
You must be signed in to change notification settings - Fork 291
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
[flow] import type
from another file does not resolve the type information
#180
Comments
react-docgen only looks at files in isolation since it doesn't know how to resolve dependencies. This is basically a duplicate of #33. A typical workaround is to process the type definition file separately to extract the type information and join the data yourself. That said, I'm open to suggestions how we could solve this, bearing in mind that the module identifier resolution process must be pluggable/exchangeable. |
At the root, this does look like a duplicate of #33. Regarding module resolution, I suspect it will have to be rather smart or reuse something from node or flow. I am unfamiliar with the code here, so not sure about the challenges, but let me just add some pertinent details. Flow types are available from:
|
I'm trying to venture down this path but I'm afraid I know little about this toolset. I presume I would:
First thing is to discover the types imported and from where. I determined how to get the information but not how to return it through the resolver/handler. I unclear if I'm on the right track or even using the full capability of this toolset. Called from our reactDocgen.parse(src, findFlowTypeImportDefinitions) // @flow
import { utils } from 'react-docgen';
import type { NodePath } from './types';
/**
* Given an AST, this function tries to find the exported flow type definition.
*/
export default function findFlowTypeImportDefinitions(
ast: ASTNode,
recast: Object,
): ?NodePath {
function importTypeDeclaration(path: NodePath) {
let definition
if (path.node.importKind === 'type') {
if (path.node.specifiers) {
// to be done in the handler?
//const specifiers = path.get('specifiers');
//specifiers.each(
// (specifier) => {
// const local = specifier.get('local');
// types.push(local.value.name);
// },
//);
// structure return representing types import?
//return {
// module: path.node.source.raw,
// types: types,
//};
definition = path;
}
}
// if(!definition) {
// return false;
// }
return false;
}
recast.visit(ast, {
visitImportDeclaration: importTypeDeclaration
});
} I've got a branch started with these experiments. Any guidance is appreciated. We need to solve this before our next major release. |
It seems that a new plugin inline's the flow types, this might solve this problem for me altogether. https://twitter.com/thejameskyle/status/870764494917582850 https://github.com/thejameskyle/babel-plugin-react-flow-props-to-prop-types |
Duplicate of #33 |
Problem
import type
from another file does not resolve the underlying type informationbreakpoints.js
used throughout the project:Hidden.js
component:Expected result
When I place the
type Breakpoints
locally in the file (noimport type
), I get the expected result:Placing every type inside the file is a non-starter though, as it severely limits reuse of types throughout the application.
The text was updated successfully, but these errors were encountered: