Use typed KclValue instead of any in sketchFromKclValue (#7144)
* use KclValue instead of any * no need for any in sketchFromKclValueOptional * simplify error reason for sketchFromKclValueOptional
This commit is contained in:
@ -361,31 +361,24 @@ function rustArtifactGraphToMap(
|
|||||||
return map
|
return map
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: In the future, make the parameter be a KclValue.
|
|
||||||
export function sketchFromKclValueOptional(
|
export function sketchFromKclValueOptional(
|
||||||
obj: any,
|
obj: KclValue | undefined,
|
||||||
varName: string | null
|
varName: string | null
|
||||||
): Sketch | Reason {
|
): 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 === 'Sketch') return obj.value
|
||||||
if (obj?.type === 'Solid') return obj.value.sketch
|
if (obj?.type === 'Solid') return obj.value.sketch
|
||||||
if (!varName) {
|
if (!varName) {
|
||||||
varName = 'a KCL value'
|
varName = 'a KCL value'
|
||||||
}
|
}
|
||||||
const actualType = obj?.value?.type ?? obj?.type
|
|
||||||
if (actualType) {
|
const actualType = obj?.type ?? 'unknown'
|
||||||
return new Reason(
|
return new Reason(
|
||||||
`Expected ${varName} to be a sketch or solid, but it was ${actualType} instead.`
|
`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.`)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: In the future, make the parameter be a KclValue.
|
|
||||||
export function sketchFromKclValue(
|
export function sketchFromKclValue(
|
||||||
obj: any,
|
obj: KclValue | undefined,
|
||||||
varName: string | null
|
varName: string | null
|
||||||
): Sketch | Error {
|
): Sketch | Error {
|
||||||
const result = sketchFromKclValueOptional(obj, varName)
|
const result = sketchFromKclValueOptional(obj, varName)
|
||||||
|
|||||||
Reference in New Issue
Block a user