Skip to content

Use typed KclValue instead of any in sketchFromKclValue #7144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
21 changes: 7 additions & 14 deletions src/lang/wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,31 +361,24 @@ function rustArtifactGraphToMap(
return map
}

// TODO: In the future, make the parameter be a KclValue.
export function sketchFromKclValueOptional(
obj: any,
obj: KclValue | undefined,
varName: string | null
): Sketch | Reason {
if (obj?.value?.type === 'Sketch') return obj.value
if (obj?.value?.type === 'Solid') return obj.value.sketch
if (obj?.type === 'Sketch') return obj.value
if (obj?.type === 'Solid') return obj.value.sketch
if (!varName) {
varName = 'a KCL value'
}
const actualType = obj?.value?.type ?? obj?.type
if (actualType) {
return new Reason(
`Expected ${varName} to be a sketch or solid, but it was ${actualType} instead.`
)
} else {
return new Reason(`Expected ${varName} to be a sketch, but it wasn't.`)
}

const actualType = obj?.type ?? 'unknown'
return new Reason(
`Expected ${varName} to be a sketch or solid, but it was ${actualType} instead.`
)
}

// TODO: In the future, make the parameter be a KclValue.
export function sketchFromKclValue(
obj: any,
obj: KclValue | undefined,
varName: string | null
): Sketch | Error {
const result = sketchFromKclValueOptional(obj, varName)
Expand Down
Loading