MCPcopy Index your code
hub / github.com/microsoft/TypeChat / appendObjectType

Function appendObjectType

typescript/src/zod/validate.ts:188–217  ·  view source on GitHub ↗
(objectType: z.ZodType)

Source from the content-addressed store, hash-verified

186 }
187
188 function appendObjectType(objectType: z.ZodType) {
189 append("{");
190 appendNewLine();
191 indent++;
192 for (let [name, type] of Object.entries((objectType._zod.def as z.core.$ZodObjectDef).shape) as [string, z.ZodType][]) {
193 let inlineComment: string | undefined;
194 if (getTypeKind(type) === "optional") {
195 const wrapperDescription = type.description;
196 if (wrapperDescription) {
197 for (const line of wrapperDescription.split("\n")) {
198 append(`// ${line}`);
199 appendNewLine();
200 }
201 }
202 append(name);
203 append("?");
204 type = (type._zod.def as z.core.$ZodOptionalDef).innerType as z.ZodType;
205 } else {
206 inlineComment = type.description;
207 append(name);
208 }
209 append(": ");
210 appendType(type);
211 append(";");
212 if (inlineComment) append(` // ${inlineComment}`);
213 appendNewLine();
214 }
215 indent--;
216 append("}");
217 }
218
219 function appendUnionOrIntersectionTypes(types: readonly z.ZodType[], minPrecedence: TypePrecedence) {
220 let first = true;

Callers 2

getZodSchemaAsTypeScriptFunction · 0.85
appendTypeDefinitionFunction · 0.85

Calls 4

appendFunction · 0.85
appendNewLineFunction · 0.85
getTypeKindFunction · 0.85
appendTypeFunction · 0.85

Tested by

no test coverage detected