makenotion / notion-sdk-js

Official Notion JavaScript Client
https://developers.notion.com/docs
MIT License
4.96k stars 593 forks source link

fix: modify response types to intersection #445

Closed devjiwonchoi closed 1 year ago

devjiwonchoi commented 1 year ago

Description

Since Response types are currently in a union, the users cannot access response objects' property directly.

Example:

const response = await notion.blocks.children.list({
  block_id: block_id,
})

const archives = response.results.filter((block) => block.archived) // Error here
Property 'archived' does not exist on type 'PartialBlockObjectResponse | BlockObjectResponse'.
Property 'archived' does not exist on type 'PartialBlockObjectResponse'.ts(2339)

Fix

Current:

https://github.com/makenotion/notion-sdk-js/blob/83ac0435379c511e3b5a879fcdb06df0e80f5eae/src/api-endpoints.ts#L10279-L10286

Fix:

// api-endpoints.ts
export type ListBlockChildrenResponse = {
    type: "block";
    block: EmptyObject;
    object: "list";
    next_cursor: string | null;
    has_more: boolean;
    results: Array<PartialBlockObjectResponse & BlockObjectResponse>; // union to intersection
};

Fixes https://github.com/makenotion/notion-sdk-js/issues/425#issuecomment-1683981412 #443

CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.

rhart92 commented 1 year ago

Unfortunately we had to remove an old .env file from the repo which required completely re-writing the commit history causing this PR's commit history to be out of date. Please re-submit this PR after pulling a fresh copy of this repo 🙏 Apologies for any inconvenience.