From b228aaae4506df39271c5ec6bcd6fcfcfa7c9089 Mon Sep 17 00:00:00 2001 From: Jonathan Tran Date: Fri, 4 Apr 2025 15:51:19 -0400 Subject: [PATCH] Fix tsc errors --- src/lang/std/sketchcombos.ts | 26 ++++++++++++++++++++++---- src/lib/trap.ts | 6 ++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/lang/std/sketchcombos.ts b/src/lang/std/sketchcombos.ts index 14debfdad..fc80572ef 100644 --- a/src/lang/std/sketchcombos.ts +++ b/src/lang/std/sketchcombos.ts @@ -1,5 +1,5 @@ import type { Node } from '@rust/kcl-lib/bindings/Node' -import { NonCodeMeta } from '@rust/kcl-lib/bindings/NonCodeMeta' +import { type NonCodeMeta } from '@rust/kcl-lib/bindings/NonCodeMeta' import { ARG_ANGLE, @@ -74,7 +74,7 @@ import type { } from '@src/lang/wasm' import { sketchFromKclValue } from '@src/lang/wasm' import type { Selections } from '@src/lib/selections' -import { cleanErrs, err } from '@src/lib/trap' +import { cleanErrs, err, isNotErr } from '@src/lib/trap' import { allLabels, getAngle, @@ -1501,16 +1501,34 @@ export function removeSingleConstraint({ ) } const toReplace = inputToReplace.key - const args = inputs.map((arg) => { + let argsPreFilter = inputs.map((arg) => { // console.log('ADAM: arg is', arg) + if (arg.type !== 'labeledArg') { + return undefined + } const k = arg.key if (k !== toReplace) { return createLabeledArg(k, arg.expr) } else { - const rawArgVersion = rawArgs.find((a) => a.key === k) + const rawArgVersion = rawArgs.find( + (a) => a.type === 'labeledArg' && a.key === k + ) + if (!rawArgVersion) { + return new Error( + `raw arg version not found while trying to remove constraint: ${JSON.stringify(arg)}` + ) + } return createLabeledArg(k, rawArgVersion.expr) } }) + const args = argsPreFilter + .filter((arg) => arg !== undefined) + .filter(isNotErr) + if (args.length !== argsPreFilter.length) { + return new Error('Error while trying to remove constraint', { + cause: argsPreFilter, + }) + } const noncode = callExp.node.nonCodeMeta return createStdlibCallExpressionKw( callExp.node.callee.name.name as ToolTip, diff --git a/src/lib/trap.ts b/src/lib/trap.ts index e62b7fcc8..13114fc76 100644 --- a/src/lib/trap.ts +++ b/src/lib/trap.ts @@ -19,6 +19,12 @@ export class Reason { } } +export function isNotErr( + value: ExcludeErr | Error +): value is ExcludeErr { + return !(value instanceof Error) +} + /** * This is intentionally *not* exported due to misuse. We'd like to add a lint. */