typescript#DiagnosticMessageChain TypeScript Examples

The following examples show how to use typescript#DiagnosticMessageChain. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: revalidate-model.ts    From typescript-exercises with MIT License 6 votes vote down vote up
export function flattenDiagnosticMessageText(
    diag: string | DiagnosticMessageChain | undefined,
    newLine: string,
    indent = 0
): string {
    if (typeof diag === 'string') {
        return diag;
    } else if (diag === undefined) {
        return '';
    }
    let result = '';
    if (indent) {
        result += newLine;

        for (let i = 0; i < indent; i++) {
            result += '  ';
        }
    }
    result += diag.messageText;
    indent++;
    if (diag.next) {
        for (const kid of diag.next) {
            result += flattenDiagnosticMessageText(kid, newLine, indent);
        }
    }
    return result;
}