Iterate over interface properties in TypeScript

You can’t, interfaces are only for compile time because javascript doesn’t support it.

What you can do is something like:

const Activity = {
    id: "",
    title: "",
    body: "",
    json: {}
}

type Activity = typeof Activity;
const headers: Array<Object> = Object.keys(Activity).map(key => {
    return { text: key, value: key }
});

(code in playground)

Leave a Comment