Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/components/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 12 additions & 1 deletion lib/components/switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -14,6 +18,12 @@ import { z } from "zod"
export interface SwitchProps extends CommonComponentProps {
type?: "spst" | "spdt" | "dpst" | "dpdt"
pinLabels?: PinLabelsProp<SchematicPinLabel>
/**
* 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
Expand All @@ -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(),
Expand Down
11 changes: 11 additions & 0 deletions tests/switch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
})