GithubHelp home page GithubHelp logo

Comments (9)

capi1O avatar capi1O commented on April 26, 2024 2

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.

gabelevi avatar gabelevi commented on April 26, 2024

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.

avikchaudhuri avatar avikchaudhuri commented on April 26, 2024

Will fix.

from flow.

Raynos avatar Raynos commented on April 26, 2024

πŸ‘ Looking forward to this for my commonJS modules

from flow.

avikchaudhuri avatar avikchaudhuri commented on April 26, 2024

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.

Raynos avatar Raynos commented on April 26, 2024

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.

Raynos avatar Raynos commented on April 26, 2024

@avikchaudhuri

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.

 avatar commented on April 26, 2024

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.

nmn avatar nmn commented on April 26, 2024

This has long been fixed with type imports etc.

from flow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.