-2

I want to use this code to generate String.

randomString(): string {
    const length = 40;
    const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    let result = '';
    for (let i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
    return result;
  }

But I get this error:

TSLint: for statements must be braced (curly)

Do you know in typescript what braces should I use?

Jota.Toledo
  • 27,293
  • 11
  • 59
  • 73
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

1 Answers1

4
for (let i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];

should be

for (let i = length; i > 0; --i) {
  result += chars[Math.floor(Math.random() * chars.length)];
}

Your IDE should propose you to automatically resolve this issue.