Skip to content

Commit e006407

Browse files
committed
more accurate type to avoid type assertion and destructure
1 parent a3be733 commit e006407

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/slang-nodes/types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ export type StrictAstNode =
460460
| YulPaths
461461
| YulPath;
462462

463+
export type PrintableCollectionNode = Extract<
464+
StrictAstNode,
465+
{ items: StrictAstNode[] }
466+
>;
467+
463468
export type CollectionNode = Extract<StrictAstNode, { items: unknown[] }>;
464469

465470
export type BinaryOperation = Extract<

src/slang-printers/print-preserving-empty-lines.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@ import { locEnd } from '../slang-utils/loc.js';
55
import type { AstPath, Doc, ParserOptions } from 'prettier';
66
import type {
77
AstNode,
8-
CollectionNode,
9-
StrictAstNode
8+
PrintableCollectionNode
109
} from '../slang-nodes/types.d.ts';
1110
import type { PrintFunction } from '../types.d.ts';
1211

1312
const { hardline } = doc.builders;
1413

1514
export function printPreservingEmptyLines(
16-
path: AstPath<CollectionNode>,
15+
path: AstPath<PrintableCollectionNode>,
1716
print: PrintFunction,
1817
options: ParserOptions<AstNode>
1918
): Doc {
2019
return path.map((childPath) => {
21-
const node = childPath.node as StrictAstNode;
20+
const { node } = childPath;
2221

2322
return [
2423
// Only attempt to prepend an empty line if `node` is not the first item

0 commit comments

Comments
 (0)