问题描述
我正在使用 Typescript 和 Prettier,每次我在函数的第一行中投射某些内容时,Prettier 都会将分号作为第一个字符。
为什么?似乎没有必要。我错了吗?
我阅读了 Rationale,但我仍然不明白为什么我们需要将第一个分号放在那里。
更漂亮的 2.2.1 Playground link
--parser typescript
--no-semi
输入:
function example() {
(this as MyType).method() // useless semicolon will be placed here
;(f as any).y = fy // the semicolon here is ok
return f
}
输出:
function example() {
;(this as MyType).method() // useless semicolon here
;(f as any).y = fy // the semicolon here is ok
return f
}
预期行为:
不能放第一个分号。
我打开了 an issue on the Prettier repo,但他们建议我在这里问。
***更新:
如果我使用更漂亮的默认值,我也有问题,请参阅此示例:
更漂亮的 2.2.1 Playground link
--parser typescript
输入:
export function inputSelect(e: MouseEvent): void {
console.log("Test this")
(e.target as HTMLInputElement)?.select();
}
输出:
export function inputSelect(e: MouseEvent): void {
console
.log("Test this")(e.target as HTMLInputElement)
?.select();
}
预期行为:
它应该将分号放在 console.log()
的末尾。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)