I was reading this and trying to implement it in Typescript.
There isn't a lot of good advice on the official doc except for using @ts-ignore
which I hate using.
So I spent like half an hour to hack this solution. I hope you enjoy.
And you are welcome.