TS solution

One solution - probably not the neatest, but it should still work.