The TypeScript Playground now supports this by Automatic Type Acquisition (ATA) https://www.typescriptlang.org/play/#handbook-4
So your original code should just work now, as it is