Skip to main content
Notion API responses often include partial objects when the full object wasn’t requested or isn’t available. The SDK provides type guard functions to help you safely distinguish between full and partial responses.

Why Type Guards?

Many Notion endpoints return union types like PageObjectResponse | PartialPageObjectResponse. Type guards let you:
  • Check if a response contains full details
  • Safely access properties that only exist on full objects
  • Get proper TypeScript type narrowing

Available Type Guards

All type guards are exported from the main package:

Page Type Guards

isFullPage

Checks if a response is a full PageObjectResponse.
Implementation: Returns true if response.object === "page" and has a url property. Example:
src/helpers.ts:186-189

Block Type Guards

isFullBlock

Checks if a response is a full BlockObjectResponse.
Implementation: Returns true if response.object === "block" and has a type property. Example:
src/helpers.ts:176-180

Data Source Type Guards

isFullDataSource

Checks if a response is a full DataSourceObjectResponse.
Implementation: Returns true if response.object === "data_source". Example:
src/helpers.ts:194-198

isFullPageOrDataSource

Checks if a response is either a full PageObjectResponse or DataSourceObjectResponse. Useful when working with search or query results.
Implementation: Checks for full data source first, otherwise checks for full page. Example:
src/helpers.ts:216-224

Database Type Guards

isFullDatabase

Checks if a response is a full DatabaseObjectResponse.
Implementation: Returns true if response.object === "database". Example:
src/helpers.ts:201-205

User Type Guards

isFullUser

Checks if a response is a full UserObjectResponse.
Implementation: Returns true if the response has a type property. Example:
src/helpers.ts:229-233

Comment Type Guards

isFullComment

Checks if a response is a full CommentObjectResponse.
Implementation: Returns true if the response has a created_by property. Example:
src/helpers.ts:237-242

Rich Text Type Guards

For rich text items, use these type guards to determine the content type:

isTextRichTextItemResponse

Implementation: Returns true if richText.type === "text". Example:
src/helpers.ts:247-251

isEquationRichTextItemResponse

Implementation: Returns true if richText.type === "equation". Example:
src/helpers.ts:256-260

isMentionRichTextItemResponse

Implementation: Returns true if richText.type === "mention". Example:
src/helpers.ts:265-269

Combining Type Guards

Type guards work well together for complex filtering:

Best Practices

Properties like url, created_time, and type-specific fields only exist on full objects. Use type guards to avoid runtime errors:
After using a type guard, TypeScript will provide full autocomplete for the narrowed type, making development easier and catching errors early.
Always consider what to do when an object is partial:

Type Definitions

All type guard functions use TypeScript’s is operator for type predicates, which tells TypeScript to narrow the type in the if block:
The type guards check runtime properties to determine which variant you have, giving you type safety at both compile time and runtime.