File tree Expand file tree Collapse file tree 3 files changed +36
-1
lines changed
Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 1+ #### Add typing to support ` readonly ` array properties of AST Node (#15127 by @auvred )
2+
3+ <!-- prettier-ignore -->
4+ ``` tsx
5+ // Input
6+ interface TestNode {
7+ readonlyArray: readonly string [];
8+ }
9+
10+ declare const path: AstPath <TestNode >;
11+
12+ path .map (() => " " , " readonlyArray" );
13+
14+ // Prettier stable
15+ interface TestNode {
16+ readonlyArray: readonly string [];
17+ }
18+
19+ declare const path: AstPath <TestNode >;
20+
21+ path .map (() => " " , " readonlyArray" );
22+ // ^ Argument of type '"readonlyArray"' is not assignable to parameter of type '"regularArray"'. ts(2345)
23+
24+ // Prettier main
25+ interface TestNode {
26+ readonlyArray: readonly string [];
27+ }
28+
29+ declare const path: AstPath <TestNode >;
30+
31+ path .map (() => " " , " readonlyArray" );
32+ ```
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ type ArrayElement<T> = T extends Array<infer E> ? E : never;
3333
3434// A union of the properties of the given object that are arrays.
3535type ArrayProperties < T > = {
36- [ K in keyof T ] : NonNullable < T [ K ] > extends any [ ] ? K : never ;
36+ [ K in keyof T ] : NonNullable < T [ K ] > extends readonly any [ ] ? K : never ;
3737} [ keyof T ] ;
3838
3939// A union of the properties of the given array T that can be used to index it.
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ interface Nested2 {
1212 kind : "2" ;
1313 item3 : Nested3 ;
1414 list3 : Nested3 [ ] ;
15+ list5 : readonly Nested3 [ ] ;
1516}
1617interface Nested3 {
1718 kind : "3" ;
@@ -155,5 +156,7 @@ function print(
155156 // @ts -expect-error
156157 path . map ( print , "item2" , "item3" ) ;
157158
159+ path . map ( print , "item2" , "list5" ) ;
160+
158161 return "" ;
159162}
You can’t perform that action at this time.
0 commit comments