extends a generic type with optional properties in typescript

You can write the printList like this:

function printList<T>(items: (T & TWithParams)[], itemAccessor: (i: T & TWithParams) => string) {
    items.forEach(i => {
        if (!i.ignore) {
            console.log(itemAccessor(i))
        }
    })
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top