2017-05-01 15 views
1

我剛剛在急速中接管了Angular 2/Redux項目。不幸的是,我不太瞭解Angular 2。我試圖用npm start來引導項目,但得到這個錯誤:使用Redux-Thunk輸入腳本給出錯誤

app/_dashboard.store.ts(54,37): error TS2345: Argument of type '(dispatch: any) => void' is not assignable to parameter of type 'Action'. 
    Property 'type' is missing in type '(dispatch: any) => void'. 

這是造成錯誤的代碼:

export const getNotificationAlerts: Function =() => { 

let url = '/myaccount/GetUserProfileAlertSettings'; 

post(url, {}, true) 
    .then(function (response) { 
     DashboardStore.dispatch((dispatch) => { 
      if (response.data) { 
       let notifications = response.data; 

       delete notifications.ResultCode; 

       dispatch({ 
        type: 'STORE_NOTIFICATIONS', 
        notifications: notifications 
       }); 
      } 
     }); 
    }) 
    .catch(function (error) { 
     DashboardStore.dispatch((dispatch) => { 
      dispatch({ 
       type: 'ERROR_STORE_NOTIFICATIONS', 
       error: error 
      }); 
     }); 
    }); 
} 

組件:

@Component({ 
moduleId: module.id, 
selector: 'dashboard-notifications', 
templateUrl: '../Templates/dashboard/notifications.html', 
animations: [ 
    trigger('notificationVisibility', [ 
     state('true', style({ opacity: 1, display: 'block' })), 
     state('false', style({ opacity: 0, display: 'none', height: '0px' })), 
     transition('*=>*', animate('0.15s')) 
    ]) 
] 
}) 
export class DashboardNotificationsComponent { 

// Initialize variables 
@Input() data: any; 
//showNotifications = 'true'; 
notificationActionSelected = false; 

constructor() { } 

processDetailsApproval: Function = (val, sender) => { 

    let thisComponet = this; 

    // Set disappear flag for class 
    this.notificationActionSelected = true; 

    if (typeof val !== 'undefined') { 
     processSenderApproval({ 
      'Status': val, 
      'RecipientId': sender.RecipientId, 
      'BusinessId': sender.BusinessId 
     }); 

    } 

    setTimeout(function() { 
     thisComponet.notificationActionSelected = false; 
    }, 500); 

} 
} 

POST功能

export const post = (url: string, data: Object, includeToken) => { 

    let params: Object = {}; 

    if (includeToken) { 
     params = addToken({}); 
    } 

    if (data) { 
     params = Object.assign({}, params, data); 
    } 

    params = qs.stringify(params); 

    return axios.post(url, params); 

} 

我花了整整一天的時間尋找解決方案,但是由於我沒有多少培訓就接管了這個項目,所以我很不確定我需要搜索什麼,甚至和答案對我沒有意義。任何線索將不勝感激。

+0

您是否附加了操作和組件?發佈完整的組件代碼以及如何導出它 –

+0

@PriyeshKumar添加了組件代碼。希望能幫助到你! –

回答

0

getNotificationAlerts函數應該爲redux-thunk返回另一個函數。我沒有使用ng2-redux,但只使用angular1 redux。 Mabe這會起作用嗎?

export const getNotificationAlerts: Function =() => { 

    let url = '/myaccount/GetUserProfileAlertSettings'; 

    return post(url, {}, true) 
    ... 
}