[英]Prettier breaks line in function definition when it has the type of returned function
I have this function:我有这个功能:
// before and after prettier
const foo = (a: number) => (b: number) => {
return a + b
}
If I run prettier it will leave everything as is (which is desired behaviour for me).如果我跑得更漂亮,它将保持原样(这对我来说是理想的行为)。
When I add type of returned function though it breaks a like for some reason.当我添加返回函数的类型时,虽然它由于某种原因打破了类似。
// before prettier
type NestedFuncType = (b: number) => number
const foo = (a: number): NestedFuncType => b => {
return a + b
}
// after prettier
type NestedFuncType = (b: number) => number
const foo =
(a: number): NestedFuncType =>
(b) => {
return a + b
}
Is there anything I can do to prevent line breaks?我能做些什么来防止换行吗? My .prettierc:
我的.prettierc:
{
"printWidth": 120,
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
}
Thanks.谢谢。
Prettier is opinionated, on purpose . Prettier 是有主见的,故意的。 You cannot change the way it formats your code, aside from a few exceptions and looking at their options doc, it does not mention any option to customize the mentioned behavoir.
你不能改变它格式化你的代码的方式,除了一些例外并查看他们的选项文档,它没有提到任何自定义提到的行为的选项。 You might consider dropping prettier and using TS ESLint instead.
您可能会考虑放弃 prettier 并改用 TS ESLint。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.