M
M
Maxim Korolsky2017-09-04 01:08:51
JavaScript
Maxim Korolsky, 2017-09-04 01:08:51

How to collect your object from Interface?

export interface IActivity {
    createdByUser: IActivityUser[];
    assignedToUser: IActivityUser[];
    activityType: IActivityType[];
    note?: string,
    finished: boolean,
    activityTime: string
}

interface IActivityType {
    id: number;
    name: string;
}

export interface IActivityShort {
    time: string;
    title: string;
    note: string;
    author: string;
}

There are some interfaces
I want to build a new object based on them
@computed public get activitiesMap(): IActivity[] {
        const result = [];

        if (this.activities) {
            this.activities.map((activity, index) => {
                console.log(activity.activityType);
                const activityShort: IActivityShort = {
                    time: activity.activityTime,
                    title: activity.activityType.name,
                    note: activity.note,
                    author: activity.createdByUser.name
                };

                result.push(activityShort);
            });
        }

        return result;
    }

title: activity.activityType.name - error here Property 'name' doesn't not exist on type
What's wrong? How to rebuild an object for yourself?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Kolesnichenko, 2017-09-04
@KolesnichenkoDS

activityTypeit's an array, it has no fieldname

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question