TypeScript: Fixed to break line and add a semi in one execution on one line long mapped types (#6420)

master
Sosuke Suzuki 2019-08-30 03:14:45 +09:00 committed by Simon Lydell
parent a8d75a1464
commit 77e79bbfa5
3 changed files with 23 additions and 2 deletions

View File

@ -453,6 +453,26 @@ const foo = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as (
)[]; )[];
``` ```
#### TypeScript: Fixed to break line and add a semicolon in one execution on one line long mapped types ([#6420] by [@sosukesuzuki])
Previously, when Prettier formatted long, one-line mapped types, it would break the line but didnt add a semicolon until you ran Prettier again (which broke Prettiers idempotency rule). Now, Prettier adds the semicolon in the first run, fixing the issue.
<!-- prettier-ignore -->
```ts
// Input
type FooBar<T> = { [P in keyof T]: T[P] extends Something ? Something<T[P]> : T[P] }
// Prettier (stable)
type FooBar<T> = {
[P in keyof T]: T[P] extends Something ? Something<T[P]> : T[P]
};
// Prettier (master)
type FooBar<T> = {
[P in keyof T]: T[P] extends Something ? Something<T[P]> : T[P];
};
```
[#5910]: https://github.com/prettier/prettier/pull/5910 [#5910]: https://github.com/prettier/prettier/pull/5910
[#6186]: https://github.com/prettier/prettier/pull/6186 [#6186]: https://github.com/prettier/prettier/pull/6186
[#6206]: https://github.com/prettier/prettier/pull/6206 [#6206]: https://github.com/prettier/prettier/pull/6206
@ -468,6 +488,7 @@ const foo = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as (
[#6307]: https://github.com/prettier/prettier/pull/6307 [#6307]: https://github.com/prettier/prettier/pull/6307
[#6340]: https://github.com/prettier/prettier/pull/6340 [#6340]: https://github.com/prettier/prettier/pull/6340
[#6412]: https://github.com/prettier/prettier/pull/6412 [#6412]: https://github.com/prettier/prettier/pull/6412
[#6420]: https://github.com/prettier/prettier/pull/6420
[@duailibe]: https://github.com/duailibe [@duailibe]: https://github.com/duailibe
[@gavinjoyce]: https://github.com/gavinjoyce [@gavinjoyce]: https://github.com/gavinjoyce
[@sosukesuzuki]: https://github.com/sosukesuzuki [@sosukesuzuki]: https://github.com/sosukesuzuki

View File

@ -3260,7 +3260,7 @@ function printPathNoParens(path, options, print, args) {
: "", : "",
": ", ": ",
path.call(print, "typeAnnotation"), path.call(print, "typeAnnotation"),
shouldBreak && options.semi ? ";" : "" ifBreak(semi, "")
]) ])
), ),
comments.printDanglingComments(path, options, /* sameIndent */ true), comments.printDanglingComments(path, options, /* sameIndent */ true),

View File

@ -32,7 +32,7 @@ export type DeepReadonly<T> = T extends any[]
: T; : T;
type NonFunctionPropertyNames<T> = { type NonFunctionPropertyNames<T> = {
[K in keyof T]: T[K] extends Function ? never : K [K in keyof T]: T[K] extends Function ? never : K;
}[keyof T]; }[keyof T];
interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {} interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {}