Fixed typescript error with embedded function