> For the complete documentation index, see [llms.txt](/llms.txt).
> The full corpus is at [llms-full.txt](/llms-full.txt).

# getAncestor

## Call Signature

> **getAncestor**\<`TMatch`\>(`snapshot`, `path`, `options`): \{ `node`: `TMatch`; `path`: `Path`; \} \| `undefined`

Defined in: get-ancestor.ts:17

Find an ancestor of the node at a given path that matches a predicate.
Does not check the node at the path itself, only its ancestors.

`mode: 'lowest'` (default) returns the nearest matching ancestor.
`mode: 'highest'` returns the outermost matching ancestor.

When `match` is a type predicate, the returned `node` narrows to that type.

### Type Parameters

#### TMatch

`TMatch` *extends* `PortableTextBlock`

### Parameters

#### snapshot

`TraversalSnapshot`

#### path

`Path`

#### options

##### match

(`node`, `path`) => `node is TMatch`

##### mode?

`"lowest"` \| `"highest"`

### Returns

\{ `node`: `TMatch`; `path`: `Path`; \} \| `undefined`

## Call Signature

> **getAncestor**(`snapshot`, `path`, `options`): \{ `node`: `PortableTextBlock`; `path`: `Path`; \} \| `undefined`

Defined in: get-ancestor.ts:28

### Parameters

#### snapshot

`TraversalSnapshot`

#### path

`Path`

#### options

##### match

(`node`, `path`) => `boolean`

##### mode?

`"lowest"` \| `"highest"`

### Returns

\{ `node`: `PortableTextBlock`; `path`: `Path`; \} \| `undefined`