2017-11-13 4 views
0

내 목표는 K에있는 모든 키의 "정확한 개체 형식"인 Entities 형식을 만드는 것입니다.여러 인덱서는 오류가 허용되지 않지만 인덱서가 아닙니다.

K은 다음과 같습니다

type SocialEntity =  Article | Thumb | Comment | Displayname | Helpful; 
type SocialEntityKind = 'articles' | 'thumbs' | 'comments' | 'displaynames' | 'helpfuls'; 


const K: {[key: SocialEntityKind]: SocialEntityKind} = { // short for SOCIAL_ENTITY_KIND 
    articles: 'articles', 
    thumbs: 'thumbs', 
    comments: 'comments', 
    displaynames: 'displaynames', 
    helpfuls: 'helpfuls' 
} 

가 지금은 [key: typeof K.*]을 설정하지만이 인덱서을 고려했습니다.

이 작업을 수행 할 수있는 쉽고 올바른 방법이 있나요 : 여기

type Entities = {| 
    [key: typeof K.articles]: { 
     [key: ArticleId]: Article 
    }, 
    [key: typeof K.thumbs]: { 
     [key: ThumbId]: Thumb 
    }, 
    [key: typeof K.comments]: { 
     [key: CommentId]: Comment 
    }, 
    [key: typeof K.displaynames]: { 
     [key: DisplaynameId]: Displayname 
    }, 
    [key: typeof K.helpfuls]: { 
     [key: HelpfulId]: Helpful 
    } 
|} 

오류의 스크린 샷이다?

답변

2

구문은 사용자가하려는 작업에 사용할 수 없습니다. Flowtype의 [key: TYPE]: TYPEusing objects as dictionaries의 구문이며 계산 된 속성 이름의 구문은 아닙니다.

형식이 string이며 articles이 아니기 때문에 원하는 방식으로 typeof을 사용할 수도 없습니다. 수동으로 키 이름을 입력해야합니다.

+0

Drats, thanks logan. – Noitidart

관련 문제