Axios, Typescript, and Promises

Viewed 14919

This may be more of a TypeScript question. I have a REST method that is called within my http library by Vue action. I'd like the resolve() method to return the typed array, but unless I do the conversion within the action.ts "then" method, I receive a '.length does not exist in type {}'

Is there any way to not have to re-cast the result to my typed array since it was already done in the http.ts method?

http.ts (partial)

getapps() {        
        return new Promise((resolve, reject) => {
            this.axios.post('/account/getapps').then((response) => {
                resolve(response.data as DomainAppType[]);
            }, (err) => {
                reject(err);
            });
         });
    }

action.ts

import { DomainAppType } from '../models/domainApps';

var actions = {
    LOGIN: function ({ commit }, params) {
        http.getapps(params.email, params.password).then(apps => {
            var appList = <DomainAppType[]>apps;
            console.log(appList.length);
        }).catch((err) => {
            console.log(JSON.stringify(err));
        })

      }
}
export default actions
1 Answers
Related