0
我需要在流動型註釋其返回一個對象的函數,我看我有幾種選擇:流動型標註函數返回類型
A)詮釋對象導出和功能
const getForecastHourly:ActionType = (query:number):ActionType => ...
B)註釋僅在功能:
const getForecastHourly = (query:number):ActionType => ...
C)上對象註釋僅導出:
const getForecastHourly:ActionType = (query:number) => ...
在我的代碼中,我使用的是版本A),但是我想知道B或C是否可以等價,哪個版本是可以理解的以及爲什麼。
// @flow
import {ActionType} from '../../types'
import 'isomorphic-fetch'
import * as api from '../../app/api'
import * as types from './forecastHourlyActionTypes'
const getForecastHourly:ActionType = (query:number):ActionType => ({
type: types.GET_FORECAST_HOURLY,
payload: new Promise((resolve, reject) => {
fetch(api.forecast(query)).then(response => {
resolve(response.json())
})
})
})
const setForecastHourlyActiveReportType:ActionType = (type:string):ActionType => ({
type: types.SET_FORECAST_HOURLY_ACTIVE_REPORT_TYPE,
payload: type
})
export { getForecastHourly, setForecastHourlyActiveReportType }
export type ActionType ={
+type:string,
+payload: Object
}