Comments (9)
Sorry @nmn but could you give an example ?
I am in the situation where there I need to require
a module by path, and I cannot get Flow to understand the declared types for this module default export.
module.js
:
const FunctionalComponent = (name: string): React$Element<*> => (<button>{name}</button>);
export default FunctionalComponent;
app.js
:
const FunctionalComponent = require('./FunctionalComponent'); // eslint-disable-line global-require
render(<FunctionalComponent/>, rootElement);
got the error Expected React component instead of CommonJS exports of ".FunctionalComponent"
I tried to declare the module in FunctionalComponent.flow.js in various ways, ex :
FunctionalComponent.flow.js
:
declare module 'FunctionalComponent'
{
declare var exports: (name: string) => React.Component;
}
but this file does not seem to be used by flow at all.
from flow.
I know there's parser support for this since I added it last night :)
We just need to add support to Flow's core to understand what the path means as a module name.
from flow.
Will fix.
from flow.
π Looking forward to this for my commonJS modules
from flow.
Huh, I just checked what we have, and it seems that at least path-based requires that don't start with /, ./, or ../ should already work with declare module "..." syntax (this is more of a documentation issue, we should explain how this works!)
In other words, you can do exactly what you suggest in the first case, and it should work.
The other cases definitely do not work currently with declare module, since we don't know what a canonical string at the declaration site should be. You suggestion of going relative to the root is a good idea, let me think about it a bit more.
from flow.
I would like to recommend that
declare module "foo/bar/mixins/MyMixin" {}
is relative not to the CWD but to the location of the declaration file.
So if the declaration file is in the foo folder it would be
declare module "bar/mixins/MyMixin" {}
This is consistent with the node lookup algorithm as well for local files.
from flow.
This is issue is important for being able to use and test flow. I would like to use flowtype with pure ES5 and have local declaration files that define the types of local files.
This would allow me to use flowtype on a non-trivial project without having to use the inline type signatures extended ES5 language.
I would not mind contributing a fix for this if you could point at the rough area of the code that needs to change for this.
from flow.
Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.
from flow.
This has long been fixed with type imports etc.
from flow.
Related Issues (20)
- Does not narrow down type after undefined/falsy check HOT 1
- Recursive/deep Partial HOT 2
- Bugs in negated `instanceof` expressions HOT 1
- [Question]: How to fix flowgen test after flow update HOT 3
- [Discussion]: Any plans to make Flow more interpopble with TS ecosystem? HOT 5
- Higher order type parameter support HOT 1
- Readme links to 404
- Strange index signature error if you use $Keys<O> instead of the equivalent literal union inside $ReadOnlyArray HOT 1
- [homebrew] automation script needs update HOT 2
- "Unxepcted identifier, expected the token ;" when using await inside of ES module HOT 3
- Can't iterate through chars in a string HOT 4
- Flow does not catch invalid switch statements HOT 1
- Conditional type only works if I inline it HOT 5
- Object with null prototype does not extend interface {} HOT 3
- Missing documentation for "render-types"? HOT 2
- Relay + graphql literals HOT 11
- [homebrew] regression test failure with 0.226.0,0.227.0 HOT 2
- FLOW BUG: This is a misplaced error HOT 3
- The `experimental.ts_syntax` doesnβt seem to do anything HOT 2
- Parameters<> does not support optional params HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flow.