当 Prettier 具有返回函数的类型时,它会在函数定义中换行
Prettier breaks line in function definition when it has the type of returned function
我有这个功能:
// before and after prettier
const foo = (a: number) => (b: number) => {
return a + b
}
如果我 运行 更漂亮,它将保持原样(这对我来说是理想的行为)。
当我添加返回函数的类型时,尽管它出于某种原因破坏了一个赞。
// 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
}
有什么办法可以防止换行吗?我的.prettierc:
{
"printWidth": 120,
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
}
谢谢。
Prettier 是 opinionated, on purpose. You cannot change the way it formats your code, aside from a few exceptions and looking at their options 文档,它没有提到任何自定义上述行为的选项。您可能会考虑放弃 prettier 并改用 TS ESLint。
我有这个功能:
// before and after prettier
const foo = (a: number) => (b: number) => {
return a + b
}
如果我 运行 更漂亮,它将保持原样(这对我来说是理想的行为)。
当我添加返回函数的类型时,尽管它出于某种原因破坏了一个赞。
// 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
}
有什么办法可以防止换行吗?我的.prettierc:
{
"printWidth": 120,
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
}
谢谢。
Prettier 是 opinionated, on purpose. You cannot change the way it formats your code, aside from a few exceptions and looking at their options 文档,它没有提到任何自定义上述行为的选项。您可能会考虑放弃 prettier 并改用 TS ESLint。