Error: Property 'properties' does not exist on type '{ object: "page"; id: string; }' - v0.4.11
See original GitHub issueDescribe the bug
When I upgrade from v0.4.9
to v0.4.11
, I get type errors in my code that look like this
Property 'properties' does not exist on type '{ object: "page"; id: string; }'
Seems like the recent type updates in the api-endpoints.ts
file has new types that look similar to the following that cause the error:
{
...
object: "page";
id: string;
created_time: string;
last_edited_time: string;
archived: boolean;
url: string;
} | {
object: "page";
id: string;
}>;
and
{
...
} | {
object: "block";
id: string;
}
To Reproduce
Node version: v16.13.0
Notion JS library version: v0.4.11
Steps to reproduce the behaviour:
Try running a similar code snippet with v0.4.11
to make a notion query and parse some data and you will notice item.properties
throws a ts(2339)
error. So will item.icon
.
export async function getBookmarks() {
const { results } = await notion.databases.query({
database_id: process.env.NOTION_BOOKMARKS_DATABASE ?? "",
filter: {
property: "Status",
select: {
equals: "Published",
},
},
});
return results.map((item) => {
const properties = item.properties;
return {
id: item.id,
emoji: item?.icon?.type === "emoji" ? item.icon.emoji : "",
createdAt:
properties.Created.type === "created_time"
? properties.Created.created_time
: "",
name:
properties.Name.type === "title"
? properties.Name.title[0].plain_text
: "",
type: properties.Type.type === "select" ? properties.Type.select : "",
url: properties.URL.type === "url" ? properties.URL.url : "",
} as Bookmark;
});
}
Expected behaviour
This wasn’t the behaviour prior to the upgrade. v0.4.9
didn’t throw these errors. These extra types seem redundant and don’t look like they belong there. Why would you have a page or block type that only has an id and no other metadata (created_time, URL, etc)?
Is this something that needs to be fixed? Is there a way to work around this?
Screenshots
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:9 (1 by maintainers)
Top GitHub Comments
At this point, we’ve gone full circle with #219 “Question about new typings”:
@notionhq/client
does not export individual typesThe DX is getting worse, while the API is improving - it’s a bit weird.
I’m having the same problem as well. To me this seems like a significant breaking change for anyone doing DB queries with Typescript. The new v 0.4.12 from a couple days ago doesn’t fix this.
I’m stuck on 0.4.9 until this issue is addressed