Skip to content

Commit

Permalink
Update readme with isFullPageOrDatabase (#452)
Browse files Browse the repository at this point in the history
* update readme with isfullpageordatabase

* fix spacing

* Fix formatting.

---------

Co-authored-by: Ryan Hart <[email protected]>
  • Loading branch information
ronovan and rhart92 authored Aug 30, 2023
1 parent e8a242a commit 7258061
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,14 @@ try {
There are several [type guards](https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types)
provided to distinguish between full and partial API responses.

| Type guard function | Purpose |
| ------------------- | -------------------------------------------------------------- |
| `isFullPage` | Determine whether an object is a full `PageObjectResponse` |
| `isFullBlock` | Determine whether an object is a full `BlockObjectResponse` |
| `isFullDatabase` | Determine whether an object is a full `DatabaseObjectResponse` |
| `isFullUser` | Determine whether an object is a full `UserObjectResponse` |
| `isFullComment` | Determine whether an object is a full `CommentObjectResponse` |
| Type guard function | Purpose |
| ---------------------- | -------------------------------------------------------------------------------------- |
| `isFullPage` | Determine whether an object is a full `PageObjectResponse` |
| `isFullBlock` | Determine whether an object is a full `BlockObjectResponse` |
| `isFullDatabase` | Determine whether an object is a full `DatabaseObjectResponse` |
| `isFullPageOrDatabase` | Determine whether an object is a full `PageObjectResponse` or `DatabaseObjectResponse` |
| `isFullUser` | Determine whether an object is a full `UserObjectResponse` |
| `isFullComment` | Determine whether an object is a full `CommentObjectResponse` |

Here is an example of using a type guard:

Expand All @@ -198,10 +199,13 @@ const fullOrPartialPages = await notion.databases.query({
database_id: "897e5a76-ae52-4b48-9fdf-e71f5945d1af",
})
for (const page of fullOrPartialPages.results) {
if (!isFullPage(page)) {
if (!isFullPageOrDatabase(page)) {
continue
}
// The page variable has been narrowed from PageObjectResponse | PartialPageObjectResponse to PageObjectResponse.
// The page variable has been narrowed from
// PageObjectResponse | PartialPageObjectResponse | DatabaseObjectResponse | PartialDatabaseObjectResponse
// to
// PageObjectResponse | DatabaseObjectResponse.
console.log("Created at:", page.created_time)
}
```
Expand Down

0 comments on commit 7258061

Please sign in to comment.