facebook / facebook/flow

[Feature request] Allow type imports in module declaration files from user land files

Đang mở
#3,122 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
feature request
Ngôn ngữ chính
Rust
Star
22.3k
Fork
1.9k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I would like to propose the ability to import types from user land(eg project files) into module declarations files(eg files living in flow-typed directory) the benefit being potentially shaving of redundant declarations from tens/hundreds of files.

The reasoning behind why this is extremely useful is inspired by some actual use cases in the projects I work on:

Suppose a typical React-Redux app that contains interfaces for Redux and Reselect libraries. The shape of a container in redux would be something like
```js
function mapStateToProps(state, props)
```
and for a reselect selector
```js
selector(state)
```
In both cases the state has always the same shape, eg `AppStateType`.
In order to properly type these functions currently you need to add type annotations in all the selectors and containers in the app specifying that `state` is of type `AppStateType`.

This is redundant and it creates boilerplate.

If such type imports from user land code into module declarations files would be permitted one could adjust both the local Redux and Reselect module declarations and type the `state` param of the containers and selectors as AppStateType once potentially shaving off the need to redeclare the state as being an `AppStateType` from hundreds of places in the app.

cc @jeffmo

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.