Skip to content
This repository was archived by the owner on Jun 26, 2026. It is now read-only.

Commit 8674911

Browse files
committed
refactor(forms): type the additionalProperties walk without as-any
The helper that binds AdditionalPropertiesField walked schema nodes through an as-any cast. Route it through a small structural interface instead, narrowing unknown values explicitly. No behaviour change — the existing array-items map test still passes. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent a9883e4 commit 8674911

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

‎apps/console/src/components/SchemaForm.tsx‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ function addAdditionalPropertiesWidgets(schema: RJSFSchema, uiSchema: UiSchema =
103103
return result
104104
}
105105

106+
/**
107+
* Minimal structural view of a JSON-schema node used by the walk below.
108+
* RJSFSchema is intersected with an `any` index signature, so reading fields
109+
* straight off it yields `any`; routing through this interface keeps the walk
110+
* typed without an `as any` cast.
111+
*/
112+
interface SchemaNode {
113+
type?: string | string[]
114+
properties?: Record<string, unknown>
115+
additionalProperties?: unknown
116+
items?: unknown
117+
}
118+
106119
/**
107120
* Resolve the uiSchema fragment for one schema node: bind the custom field to
108121
* an additionalProperties map, recurse into nested objects, or recurse into
@@ -112,30 +125,30 @@ function bindAdditionalProperties(
112125
fieldSchema: RJSFSchema,
113126
uiNode: UiSchema | undefined,
114127
): UiSchema | undefined {
115-
const node = fieldSchema as any
128+
const node: SchemaNode = fieldSchema
116129

117130
const isAdditionalPropertiesMap =
118131
node.type === "object" &&
119132
(!node.properties || Object.keys(node.properties).length === 0) &&
120133
typeof node.additionalProperties === "object" &&
121-
node.additionalProperties !== null &&
122-
node.additionalProperties !== true
134+
node.additionalProperties !== null
123135

124136
if (isAdditionalPropertiesMap) {
125137
return { ...uiNode, "ui:field": "AdditionalPropertiesField" }
126138
}
127139

128140
if (node.properties) {
129-
return addAdditionalPropertiesWidgets(fieldSchema, uiNode as UiSchema)
141+
return addAdditionalPropertiesWidgets(fieldSchema, uiNode)
130142
}
131143

144+
const items = node.items
132145
if (
133146
node.type === "array" &&
134-
node.items &&
135-
typeof node.items === "object" &&
136-
!Array.isArray(node.items)
147+
items &&
148+
typeof items === "object" &&
149+
!Array.isArray(items)
137150
) {
138-
const itemsUi = bindAdditionalProperties(node.items as RJSFSchema, (uiNode as any)?.items)
151+
const itemsUi = bindAdditionalProperties(items as RJSFSchema, uiNode?.items)
139152
if (itemsUi !== undefined) {
140153
return { ...uiNode, items: itemsUi }
141154
}

0 commit comments

Comments
 (0)