if (!node || node.type !== type) {
        throw new Error(
            `Expected node of type ${type}, but got ` +
            (node ? `node of type ${node.type}` : String(node)));
    }
Asserts that the node is of the given type and returns it with stricter
typing. Throws if the node's type does not match.