Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of parenthesis with {Optional}IndexedAccess
- Loading branch information
Showing
6 changed files
with
94 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!-- | ||
4. Fill in a title, the PR number and your user name. | ||
5. Optionally write a description. Many times it’s enough with just sample code. | ||
6. Change ```jsx to your language. For example, ```yaml. | ||
7. Change the `// Input` and `// Prettier` comments to the comment syntax of your language. For example, `# Input`. | ||
8. Choose some nice input example code. Paste it along with the output before and after your PR. | ||
--> | ||
|
||
#### Fix handling of parenthesis with Flow's {Optional}IndexedAccess (#11051 by @gkz) | ||
|
||
Add parens when required. | ||
|
||
<!-- prettier-ignore --> | ||
```jsx | ||
// Input | ||
type A = (T & S)['bar']; | ||
type B = (T | S)['bar']; | ||
type C = (?T)['bar']; | ||
type D = (typeof x)['bar']; | ||
type E = (string => void)['bar']; | ||
|
||
// Prettier stable | ||
type A = T & S["bar"]; | ||
type B = T | S["bar"]; | ||
type C = ?T["bar"]; | ||
type D = typeof x["bar"]; | ||
type E = (string) => void["bar"]; | ||
|
||
|
||
// Prettier main | ||
type A = (T & S)["bar"]; | ||
type B = (T | S)["bar"]; | ||
type C = (?T)["bar"]; | ||
type D = (typeof x)["bar"]; | ||
type E = ((string) => void)["bar"]; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
const x: Obj['bar'] = 1; | ||
|
||
type A = (T & S)['bar']; | ||
type B = (T | S)['bar']; | ||
type C = (?T)['bar']; | ||
type D = (typeof x)['bar']; | ||
type E = (string => void)['bar']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
tests/format/flow/optional-indexed-access/optional-indexed-access.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
type A = Obj?.['foo']; | ||
|
||
type B = Obj?.['foo']['bar']; | ||
|
||
type C = Obj['foo']?.['bar']; | ||
|
||
type D = (Obj?.['foo'])['bar']; | ||
type E = (T & S)?.['bar']; | ||
type F = (T | S)?.['bar']; | ||
type G = (?T)?.['bar']; | ||
type H = (typeof x)?.['bar']; | ||
type I = (string => void)?.['bar']; |