From 0e63047191e9f1856bc1ab4d3ea01fa9212f7e51 Mon Sep 17 00:00:00 2001 From: seveibar Date: Sun, 17 Nov 2024 19:54:24 -0800 Subject: [PATCH] fix types --- .../stringify-dsn-json.ts | 27 ------------------- .../parse-dsn-to-dsn-json.ts | 6 ++--- tests/dsn-pcb/stringify-dsn-json.test.ts | 6 ++--- 3 files changed, 6 insertions(+), 33 deletions(-) diff --git a/lib/dsn-pcb/circuit-json-to-dsn-json/stringify-dsn-json.ts b/lib/dsn-pcb/circuit-json-to-dsn-json/stringify-dsn-json.ts index 428ea00..396157f 100644 --- a/lib/dsn-pcb/circuit-json-to-dsn-json/stringify-dsn-json.ts +++ b/lib/dsn-pcb/circuit-json-to-dsn-json/stringify-dsn-json.ts @@ -138,30 +138,3 @@ export const stringifyDsnJson = (dsnJson: DsnPcb): string => { return result } - -function convertSessionToPcb(session: DsnSession): DsnPcb { - const pcb: DsnPcb = { - filename: session.filename, - parser: session.routes.parser, - resolution: session.routes.resolution, - unit: "um", - structure: { - layers: [], - boundary: { path: { layer: "", width: 0, coordinates: [] } }, - via: "", - rule: { width: 0, clearances: [] } - }, - placement: { components: session.placement.components }, - library: { images: [], padstacks: [] }, - network: { nets: [], classes: [] }, - wiring: { - wires: session.routes.network_out.nets.flatMap(net => - net.wires.map(wire => ({ - ...wire, - net: net.name - })) - ) - } - } - return pcb -} diff --git a/lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts b/lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts index 6a7729d..aa95b45 100644 --- a/lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts +++ b/lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts @@ -318,13 +318,13 @@ function processPath(nodes: ASTNode[]): Path { typeof nodes[startIndex + 1].value === "number" ) { path.layer = nodes[startIndex].value - path.width = nodes[startIndex + 1].value + path.width = nodes[startIndex + 1].value as number // Process coordinates after layer and width for (let i = startIndex + 2; i < nodes.length; i++) { const coordNode = nodes[i] if (coordNode?.type === "Atom" && typeof coordNode.value === "number") { - path.coordinates.push(coordNode.value) + path.coordinates!.push(coordNode.value) } } } else { @@ -332,7 +332,7 @@ function processPath(nodes: ASTNode[]): Path { for (let i = startIndex; i < nodes.length; i++) { const node = nodes[i] if (node?.type === "Atom" && typeof node.value === "number") { - path.coordinates.push(node.value) + path.coordinates!.push(node.value) } } } diff --git a/tests/dsn-pcb/stringify-dsn-json.test.ts b/tests/dsn-pcb/stringify-dsn-json.test.ts index 1e89761..71c645c 100644 --- a/tests/dsn-pcb/stringify-dsn-json.test.ts +++ b/tests/dsn-pcb/stringify-dsn-json.test.ts @@ -6,12 +6,12 @@ import testDsnFile from "../assets/testkicadproject/testkicadproject.dsn" with { import { expect, test } from "bun:test" test("stringify dsn json", () => { - const dsnJson = parseDsnToDsnJson(testDsnFile) + const dsnJson = parseDsnToDsnJson(testDsnFile) as DsnPcb const dsnString = stringifyDsnJson(dsnJson) - const reparsedJson = parseDsnToDsnJson(dsnString) + const reparsedJson = parseDsnToDsnJson(dsnString) as DsnPcb for (const key of Object.keys(reparsedJson) as Array) { - expect(reparsedJson[key]).toEqual(dsnJson[key]) + expect(reparsedJson[key]).toEqual(dsnJson[key] as any) } // Test that we can parse the generated string back to the same structure