question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Property 'properties' does not exist on type '{ object: "page"; id: string; }' - v0.4.11

See original GitHub issue

Describe 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 image image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
TheMrZZcommented, Feb 4, 2022

At this point, we’ve gone full circle with #219 “Question about new typings”:

  • @notionhq/client does not export individual types
  • We were able to extract them before using some complicated methods
  • But now that the response include partial pages, even that doesn’t work anymore

The DX is getting worse, while the API is improving - it’s a bit weird.

2reactions
alexeaglesoncommented, Jan 8, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript : Property does not exist on type 'object'
Property "country" doesn't exist on type "object". Is this a correct way to loop through each object in array and compare the object...
Read more >
Property does not exist on type Object in TypeScript
The "Property does not exist on type Object" error occurs when we try to access a property that is not contained in the...
Read more >
Typescript error: properties.Date.date does not exist #154
A clear and concise description of what you expected to happen. date is declared as an optional type of Date.
Read more >
Typescript Type System: How Does it Really Work ...
Let's have a look at the error message we get: Error:(54, 6) TS2339:Property 'name' does not exist on type '{}'. So what is...
Read more >
Fix - Property does not exist on type '{}' in TypeScript
Fix – Property does not exist on type '{}' in TypeScript ; const · = {}; ; // Explicitly define the object type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found