简体   繁体   English

TSLint:for 语句必须加括号(卷曲)

[英]TSLint: for statements must be braced (curly)

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?你知道在打字稿中我应该使用什么大括号吗?

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.您的 IDE 应该建议您自动解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM