diff --git a/lib/components/chip.ts b/lib/components/chip.ts index 97b997cb..9cda0e9c 100644 --- a/lib/components/chip.ts +++ b/lib/components/chip.ts @@ -142,7 +142,7 @@ const connectionTarget = z .or(z.array(z.string()).readonly()) .or(z.array(z.string())) -const noConnectProp = z +export const noConnectProp = z .array(schematicPinLabel) .readonly() .or(z.array(schematicPinLabel)) diff --git a/lib/components/switch.ts b/lib/components/switch.ts index 12b800df..e6a06ada 100644 --- a/lib/components/switch.ts +++ b/lib/components/switch.ts @@ -5,7 +5,11 @@ import { } from "lib/common/layout" import { connectionTarget } from "lib/common/connectionsProp" import type { SchematicPinLabel } from "lib/common/schematicPinLabel" -import { type PinLabelsProp, pinLabelsProp } from "lib/components/chip" +import { + noConnectProp, + type PinLabelsProp, + pinLabelsProp, +} from "lib/components/chip" import type { Connections } from "lib/utility-types/connections-and-selectors" import { expectTypesMatch } from "lib/typecheck" @@ -14,6 +18,12 @@ import { z } from "zod" export interface SwitchProps extends CommonComponentProps { type?: "spst" | "spdt" | "dpst" | "dpdt" pinLabels?: PinLabelsProp + /** + * Pin names that should not be connected to anything. Marks the + * corresponding source ports with do_not_connect so downstream DRC checks + * skip them (see tscircuit/tscircuit#4443). + */ + noConnect?: readonly SchematicPinLabel[] | SchematicPinLabel[] isNormallyClosed?: boolean spdt?: boolean spst?: boolean @@ -36,6 +46,7 @@ export const switchProps = commonComponentProps dpst: z.boolean().optional(), dpdt: z.boolean().optional(), pinLabels: pinLabelsProp.optional(), + noConnect: noConnectProp.optional(), simSwitchFrequency: frequency.optional(), simCloseAt: ms.optional(), simOpenAt: ms.optional(), diff --git a/tests/switch.test.ts b/tests/switch.test.ts index c9835670..430dca4f 100644 --- a/tests/switch.test.ts +++ b/tests/switch.test.ts @@ -42,3 +42,14 @@ test("should parse switch props with connections", () => { const parsedProps = switchProps.parse(rawProps) expect(parsedProps.connections?.pin1).toBe(".U1 > .pin1") }) + +test("should parse switch props with noConnect pins", () => { + const rawProps: SwitchProps = { + name: "switch", + type: "spdt", + noConnect: ["pin3"], + } + + const parsedProps = switchProps.parse(rawProps) + expect(parsedProps.noConnect).toEqual(["pin3"]) +})