function getExpectTypeFailures()

in src/rules/expectRule.ts [351:385]


function getExpectTypeFailures(
        sourceFile: SourceFile,
        typeAssertions: Map<number, string>,
        checker: TsType.TypeChecker,
        ts: typeof TsType,
        ): ExpectTypeFailures {
    const unmetExpectations: Array<{ node: TsType.Node, expected: string, actual: string }> = [];
    // Match assertions to the first node that appears on the line they apply to.
    // `forEachChild` isn't available as a method in older TypeScript versions, so must use `ts.forEachChild` instead.
    ts.forEachChild(sourceFile, function iterate(node) {
        const line = lineOfPosition(node.getStart(sourceFile), sourceFile);
        const expected = typeAssertions.get(line);
        if (expected !== undefined) {
            // https://github.com/Microsoft/TypeScript/issues/14077
            if (node.kind === ts.SyntaxKind.ExpressionStatement) {
                node = (node as TsType.ExpressionStatement).expression;
            }

            const type = checker.getTypeAtLocation(getNodeForExpectType(node, ts));

            const actual = type
                ? checker.typeToString(type, /*enclosingDeclaration*/ undefined, ts.TypeFormatFlags.NoTruncation)
                : "";

            if (!expected.split(/\s*\|\|\s*/).some(s => actual === s || matchReadonlyArray(actual, s))) {
                unmetExpectations.push({ node, expected, actual });
            }

            typeAssertions.delete(line);
        }

        ts.forEachChild(node, iterate);
    });
    return { unmetExpectations, unusedAssertions: typeAssertions.keys() };
}