2016-06-23 8 views
4

then約束に渡されたデータ構造のTypescriptエラーを取り除くにはどうすればよいですか?次のコードについてプロパティ 'count'が型 '{}'に存在しません

Property 'count' does not exist on type '{}'

私は次のエラーを取得しています、私は推測してい

this.userData.getSocialLinks(this.navParams.get('image_owner_id')).then(socialLinks => { 
    var i = 0; 
    for (i=0; i < socialLinks.count; i++) { 
    if (socialLinks.results[i].social_type == 'TW') { 
     this.profile.twitter = socialLinks.results[i].social_address; 
     this.isExistingTW = true; 
     this.twEntryID = socialLinks.results[i].id; 
    } 
    else if (socialLinks.results[i].social_type == 'IN') { 
     this.profile.instagram = socialLinks.results[i].social_address; 
     this.isExistingIN = true; 
     this.inEntryID = socialLinks.results[i].id; 
    } 
    } 
}); 

私は何とかsocialLinksを定義する必要がなく、どこうまくできません。

答えて

5

標準的な方法は、インターフェースのいくつかの種類を作成し、タイプとしてそれを使用することである:ここで

// describe what is coming  
export interface IData<T> { 
    count: number;  
    results: T[]; 
} 

// use that IData 
this.userData 
.getSocialLinks(this.navParams.get('image_owner_id')) 
.then((socialLinks: IData<any>) => { 

、例えば、Tが何であるかをより明確に存在しますIPerson ...我々は完全にthat here

+1

作品のおかげでIData<IPerson>

プレイを使用することができます。 –

関連する問題