Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Inconsistent type: Cursor for parameters is string|undefined but for responses is string|null #498

Open
jcbages opened this issue Mar 27, 2024 · 1 comment

Comments

@jcbages
Copy link

jcbages commented Mar 27, 2024

Report bugs here only for the Node JavaScript library.

If you're having problems using Notion's API, or have any other feedback about the API including feature requests for the JavaScript library, please email support at developers@makenotion.com.

Describe the bug
When calling something like database.query that receives a cursor as a parameter, its type is string | undefined as it's start_cursor:?string. However, the returned cursor from the response is of type string | null. This causes issues when looping to obtain multiple pages while reassigning the cursor variable as the initial typing of the cursor variable will conflict with one of these.

I checked the type definitions and this is the case for all calls that receive and return a cursor. This is easy to workaround but it degrades the typing experience a little.

To Reproduce
Node version:
Notion JS library version:
2.2.14

Steps to reproduce the behavior:

let databaseId = '<some_id>';
let entries = [];
let cursor: string | null = null;
let entries = [];

while (true) {
    const { results, has_more, next_cursor } = await this.notion.databases.query({
        database_id: databaseId,
        start_cursor: cursor
    });

    cursor = next_cursor;
    entries.push(...results);

    if (!has_more) {
        break;
    }
}

return entries;

Expected behavior
Expected: No typing issues
Got: Type 'string | null' is not assignable to type 'string | undefined'.

If we change the type of the cursor to be string | undefined then the error happens at cursor = next_cursor saying: Type 'string | undefined' is not assignable to type 'string | null'.

Additional context
Happy to make a PR for this :)

@Sho-ki
Copy link

Sho-ki commented May 5, 2024

I made a PR for this issue. #510

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants