We have a function here that fails sometimes. We want to debug it. We can use console.group to group the logs for this function together. But we need

TypeScript "using" keyword and console.group are a match made in heaven

submited by
Style Pass
2024-03-29 13:00:04

We have a function here that fails sometimes. We want to debug it. We can use console.group to group the logs for this function together. But we need to remember to close the group at the end of the function. If we forget, the groups will continue ad-infinitum, every time the function is called.

But suppose it is a hairy function with many returns. It’s easy to forget to close the group. We can use the using keyword to ensure that the group is closed when the function returns. First we need to define a disposable resource:

Leave a Comment