JS code converted to TypeScript