Skip to content

Commit 7035317

Browse files
committed
check property name
1 parent f3f7503 commit 7035317

4 files changed

Lines changed: 8 additions & 2 deletions

File tree

changelog_unreleased/typescript/14042.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
a as (typeof node.children)[number]
77
a as (typeof node.children)[]
88
a as ((typeof node.children)[number])[]
9+
a as number[(typeof node.children)]
910

1011
// Prettier stable
1112
a as typeof node.children[number];
1213
a as typeof node.children[];
1314
a as typeof node.children[number][];
15+
a as number[typeof node.children];
1416

1517
// Prettier main
1618
a as (typeof node.children)[number];
1719
a as (typeof node.children)[];
1820
a as (typeof node.children)[number][];
21+
a as number[typeof node.children];
1922
```

src/language-js/needs-parens.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ function needsParens(path, options) {
458458
);
459459
case "TSTypeQuery":
460460
return (
461-
name === "objectType" &&
462-
(parent.type === "TSIndexedAccessType" || parent.type === "TSArrayType")
461+
(name === "objectType" && parent.type === "TSIndexedAccessType") ||
462+
(name === "elementType" && parent.type === "TSArrayType")
463463
);
464464
case "ArrayTypeAnnotation":
465465
return parent.type === "NullableTypeAnnotation";

tests/format/typescript/typeof/__snapshots__/jsfmt.spec.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ printWidth: 80
99
a as (typeof node.children)[number]
1010
a as (typeof node.children)[]
1111
a as ((typeof node.children)[number])[]
12+
a as number[(typeof node.children)]
1213
1314
=====================================output=====================================
1415
a as (typeof node.children)[number];
1516
a as (typeof node.children)[];
1617
a as (typeof node.children)[number][];
18+
a as number[typeof node.children];
1719
1820
================================================================================
1921
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
a as (typeof node.children)[number]
22
a as (typeof node.children)[]
33
a as ((typeof node.children)[number])[]
4+
a as number[(typeof node.children)]

0 commit comments

Comments
 (0)