(jsonObject: object)
| 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"), |
nothing calls this directly
no test coverage detected