Skip to content

Significant parentheses removed from Flow types #17186

@hurrymaplelad

Description

@hurrymaplelad

Prettier 2.8.8
Playground link - Not supported, Flow parser too old

Input:

type T<U> = 'a' | ('b' extends U ? 'c' : empty);

Output:

type T<U> = 'a' | 'b' extends U ? 'c' : empty;

Expected output:

type T<U> = 'a' | ('b' extends U ? 'c' : empty);

Why?

Removing the parens changes the Flow type:

// Option 1:
type T1<U> = ('a' | 'b') extends U ? 'c' : empty;
// T1<'a' | 'b'> -> 'c'
// T1<'a'> -> empty
// T1<'b'> -> empty

// Option 2:
type T2<U> = 'a' | ('b' extends U ? 'c' : empty);
// T2<'a' | 'b'> -> 'a' | 'c'
// T2<'a'> -> 'a'
// T2<'b'> -> 'c'

// Both get Prettier'd to:
type T3<U> = 'a' | 'b' extends U ? 'c' : empty;
// which is equivalent to Option 1

Metadata

Metadata

Assignees

Labels

lang:flowIssues affecting Flow-specific constructs (not general JS issues)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions