How do I include output parameters in a function with Typescript?

Not currently.

You can return an object that can contain more than one property.

return { k1: 5, k2: 99 };

You can combine this with destructuring so the intermediate object becomes invisible…

function myFunction() {
    return { k1: 5, k2: 99 };
}

const { k1, k2 } = myFunction();

console.log(k1);
console.log(k2);

You could also achieve the same with a tuple, but this is pretty readable.

Leave a Comment