2017-03-29 55 views
1

我有以下組成部分:流型進口類型 - 名稱已經綁定

// @flow 

import React from 'react'; 

import TEA_DATA from './Tea.data'; 
import TeaInfo from './TeaInfo.component'; 

const Tea =() => <TeaInfo teaData={TEA_DATA}/>; 

export default Tea; 

然後,我有以下Tea.data.types.js文件:

// @flow 

export type id = string; 
export type image = string; 
export type header = string; 
export type text = Array<string>; 
export type brewTime = Array<any>; 

export type TEA_DATA = { 
    id: id, 
    image: image, 
    header: header, 
    text: text, 
    brewTime: brewTime 
}; 

然後,我有以下tea.data.js文件:

// @flow 

import black from '../images/blacktea.png'; 
import white from '../images/whitetea.png'; 
import oolong from '../images/oolongtea.png'; 
import green from '../images/greentea.png'; 

import type TEA_DATA from './Tea.data.types'; 

const TEA_DATA = [{ 
    id: 'wtid', 
    image: white, 
    header: 'White tea', 
    text: [ 
    "Currently there is no generally accepted definition of white tea and very little international agreement - some sources use the term to refer to tea that is merely dried with no additional processing, some to tea made from the buds and immature tea leaves picked shortly before the buds have fully opened and allowed to wither and dry in natural sun,[citation needed] while others include tea buds and very young leaves which have been steamed or fired before drying. Most definitions agree, however, that white tea is not rolled or oxidized, resulting in a flavour characterized as \"lighter\" than green or traditional black teas.", 
    "In spite of its name, brewed white tea is pale yellow. Its name derives from the fine silvery-white hairs on the unopened buds of the tea plant, which give the plant a whitish appearance. It is harvested primarily in China, mostly in the Fujian province, but more recently produced in Eastern Nepal, Taiwan, Northern Thailand, Galle (Southern Sri Lanka) and India." 
    ], 
    brewTime: { 
    mild: 1, 
    strong: 3 
    } 
}...]; 

export default TEA_DATA; 

按照flow docs這是導入的正確方法數據類型,但我收到以下錯誤:

src/Tea/Tea.data.js:10 10: const TEA_DATA = [{ ^^^^^^^^ TEA_DATA. name is already bound 8: import type TEA_DATA from './Tea.data.types'; ^^^^^^^^ type TEA_DATA

src/Tea/Tea.data.js:58 58: export default TEA_DATA; ^^^^^^^^ TEA_DATA. type referenced from value position 8: import type TEA_DATA from './Tea.data.types'; ^^^^^^^^ type TEA_DATA

我在做什麼錯?

回答

0

你只需要給你的類型命名一些不同的東西。流程不允許您在相同範圍內同時使用同名的類型和值。您已導入TEA_DATA類型,並且您也在同一個文件中命名了常量TEA_DATA

而且,在這種情況下,你應該使用

import type {TEA_DATA} from './Tea.data.types'; 

(注意,解構大括號),這樣就只導入型TEA_DATA而不是整個模塊。