[typescript] union types incorrectly indented after comments
See original GitHub issuePrettier 1.16.4 Playground link
--parser typescript
Input:
export type TransformedSource = {
code: string;
map?:
// copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/363cdf403a74e0372e87bbcd15eb1668f4c5230b/types/babel__core/index.d.ts#L371-L379
| {
version: number;
sources: string[];
names: string[];
sourceRoot?: string;
sourcesContent?: string[];
mappings: string;
file: string;
}
| string
| null;
};
export type TransformedSource = {
code: string,
map?: // copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/363cdf403a74e0372e87bbcd15eb1668f4c5230b/types/babel__core/index.d.ts#L371-L379
| {
version: number,
sources: string[],
names: string[],
sourceRoot?: string,
sourcesContent?: string[],
mappings: string,
file: string
}
| string
| null
};
Output:
export type TransformedSource = {
code: string;
map?: // copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/363cdf403a74e0372e87bbcd15eb1668f4c5230b/types/babel__core/index.d.ts#L371-L379
| {
version: number;
sources: string[];
names: string[];
sourceRoot?: string;
sourcesContent?: string[];
mappings: string;
file: string;
}
| string
| null;
};
export type TransformedSource = {
code: string;
map?: // copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/363cdf403a74e0372e87bbcd15eb1668f4c5230b/types/babel__core/index.d.ts#L371-L379
| {
version: number;
sources: string[];
names: string[];
sourceRoot?: string;
sourcesContent?: string[];
mappings: string;
file: string;
}
| string
| null;
};
Second Output:
export type TransformedSource = {
code: string;
map?: // copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/363cdf403a74e0372e87bbcd15eb1668f4c5230b/types/babel__core/index.d.ts#L371-L379
| {
version: number;
sources: string[];
names: string[];
sourceRoot?: string;
sourcesContent?: string[];
mappings: string;
file: string;
}
| string
| null;
};
export type TransformedSource = {
code: string;
map?: // copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/363cdf403a74e0372e87bbcd15eb1668f4c5230b/types/babel__core/index.d.ts#L371-L379
| {
version: number;
sources: string[];
names: string[];
sourceRoot?: string;
sourcesContent?: string[];
mappings: string;
file: string;
}
| string
| null;
};
Expected behavior: For the output to become the second result after a single prettier run. This happens using babylon and flow parser as well.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
[indent] incorrect treatment of multi-line parameter types #880
This problem compounds a bit when you've got typescript specific nodes within typescript specific nodes. As you've then got hacked together ...
Read more >Handbook - Unions and Intersection Types - TypeScript
Union Types * If 'padding' is a number, then that number of spaces is added to the left side. The problem with...
Read more >Typescript union and intersection give unintuitive and wrong ...
Ultimately your Animal type is a huge awful union, and if you assign a value that matches none of those, the compiler is...
Read more >Google TypeScript Style Guide
Omit comments that are redundant with TypeScript. For example, do not declare types in @param or @return blocks, do not write @implements ,...
Read more >Why not de-indent regions? it'll look so much more ... - Reddit
A place where a comment is not always enough to delimit an area as you ... typescript and have clearly defined string options...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, that’s what happens on the second run, in addition to a deletion of a blank line.
Maybe simpler to see:
Start:
Diff after running prettier once:
Diff after running prettier twice:
Diff between first and second run of prettier:
The idempotence issue is gone, but the indentation after the comment is off:
Prettier 2.0.5 Playground link
Input:
Output: