facebook / flow

Adds static typing to JavaScript to improve developer productivity and code quality.
https://flow.org/
MIT License
22.08k stars 1.86k forks source link

Import entire flow module #5827

Closed pronebird closed 6 years ago

pronebird commented 6 years ago

Documentation states that such entities as React.Node are not automatically made available with Javascript import of React. And so documentation suggests to use the following:

import * as React from 'react';

Which is great but then this doesn't work if I want to reimport the React.Component into the scope inline, for example:

import * as React, { Component } from 'react'; // BAD
import React, { Component } from 'react'; // GOOD

Is it possible to scope the flow type imports, for example React:

import React, { Component } from 'react'; // that's my beeswax
import type * as React from 'react'; // that's flow beeswax

It would be great to either:

  1. extend import type to import the entire module into the alias, such as following the same JS practice:
import type * as React from 'react';

= or =

  1. import the flow types with regular imports too and entirely get rid of awkward import type thing.

What do you think?

ghost commented 6 years ago

Types can be imported similarly to a named export:

import React, { Component, type Node, type ElementProps, ... } from "react";
TrySound commented 6 years ago

Just use always named exports

import * as React from 'react';
const { Component } = React;

Someday module.exports will be removed from react and all you imports will be changed. It's much easier to do things right in the beginning.

pronebird commented 6 years ago

Thanks for suggestions!