2017-05-01 3 views
1

Ich habe gerade ein Angular 2/Redux-Projekt in Eile übernommen. Ich kenne Angular 2 leider nicht sehr gut. Ich versuche, das Projekt mit npm start aber immer diese Fehlermeldung Bootstrap:Typoskript mit Redux-Thunk gibt Fehler

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'. 

Dies ist der Code, der den Fehler verursacht:

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 
      }); 
     }); 
    }); 
} 

Komponente:

@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); 

} 
} 

Die Funktion 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); 

} 

Ich habe den ganzen Tag nach Lösungen gesucht, aber da ich dieses Projekt ohne viel Training übernommen habe, bin ich mir sehr unsicher, wonach ich suchen muss, und Antworten ergeben für mich keinen Sinn. Alle Leads würden geschätzt werden.

+0

Haben Sie Aktionen und Komponenten angefügt? Veröffentlichen Sie den vollständigen Komponentencode und wie Sie ihn exportieren –

+0

@PriyeshKumar hat den Komponentencode hinzugefügt. Ich hoffe es hilft! –

Antwort

0

Die Funktion getNotificationAlerts sollte eine weitere Funktion für redux-thunk zurückgeben. Ich habe nicht mit ng2-redux gearbeitet, sondern nur mit angular1 redux. Mabe wird das funktionieren?

export const getNotificationAlerts: Function =() => { 

    let url = '/myaccount/GetUserProfileAlertSettings'; 

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