为什么可以“ typescript”无宽恕的操作员(!)处于下一行的开头?

发布于 2025-02-10 04:07:51 字数 419 浏览 1 评论 0 原文

以下代码无法在带有或不带有括号的打字稿中编译()

const foo: string | undefined = undefined;

const a = ("something very long and take all this line"
    as any);

const b = (foo // Could be something very long as well
    !.toString());

有趣的是,没有!。,, .toString()甚至?。

为什么会发生这种情况?假设代码样式每行具有最大的字符,我该如何将其移至新行?我尝试将它们包裹在括号()或将 \ 放在行结尾时,无效。

The following code cannot be compiled in TypeScript with or without the parentheses ():

const foo: string | undefined = undefined;

const a = ("something very long and take all this line"
    as any);

const b = (foo // Could be something very long as well
    !.toString());

Interestingly, without the !., .toString() or even ?.toString() would work well on the new line.

Why is this happening? Assuming a code style that has maximum character per line, how do I move these to the new line? I have tried wrapping them in parentheses () or put a \ at the end of the line, none works.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文