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

Function validate

typescript/src/ts/validate.ts:52–74  ·  view source on GitHub ↗
(jsonObject: object)

Source from the content-addressed store, hash-verified

50 return validator;
51
52 function validate(jsonObject: object) {
53 const moduleResult = validator.createModuleTextFromJson(jsonObject);
54 if (!moduleResult.success) {
55 return moduleResult;
56 }
57 const program = createProgramFromModuleText(moduleResult.data, rootProgram);
58 const syntacticDiagnostics = program.getSyntacticDiagnostics();
59 const programDiagnostics = syntacticDiagnostics.length ? syntacticDiagnostics : program.getSemanticDiagnostics();
60 if (programDiagnostics.length) {
61 const checker = program.getTypeChecker();
62 const diagnostics = programDiagnostics.map(d => {
63 const message = ts.flattenDiagnosticMessageText(d.messageText, "\n");
64 // TS error 2740 truncates the missing-properties list to 4 items ("and N more").
65 // Use the type checker to reconstruct the full list of missing required properties.
66 if (d.code === 2740 && d.file && d.start !== undefined) {
67 return expandMissingPropertiesMessage(checker, d.file, d.start) ?? message;
68 }
69 return message;
70 }).join("\n");
71 return error(diagnostics);
72 }
73 return success(jsonObject as T);
74 }
75
76 /**
77 * For TypeScript error 2740 (missing required properties, truncated with "and N more"),

Callers

nothing calls this directly

Calls 5

errorFunction · 0.90
successFunction · 0.90

Tested by

no test coverage detected