Unable To Set Parent As database_id When Creating A Page With Notion SDK

56 Views Asked by At

I'm trying to make this request:

  const response = await notion.pages.create({
    parent: {
      database_id: tasksDatabaseId,
      type: "database_id",
    },
    properties,
  });

Which works fine until I add the time_zone property to my date property here:

  const properties = {
    [tasksTitlePropertyName]: {
      "title": [
        {
          "text": {
            "content": values.title
          }
        }
      ]
    },
    [tasksStatusPropertyName]: {
      "status": {
        "name": values.status
      }
    },
    [tasksDuePropertyName]: {
      "date": {
        "start": values.dueDate,
        "time_zone": "Europe/London"
      }
    }
  };

Then I get an error:

Types of property 'parent' are incompatible. Property 'page_id' is missing in type '{ database_id: any; type: "database_id"; }' but required in type '{ page_id: string; type?: "page_id" | undefined; }'.

Argument of type '{ parent: { database_id: any; type: "database_id"; }; properties: { [x: number]: { title: { text: { content: string; }; }[]; status?: undefined; date?: undefined; } | { status: { name: string; }; title?: undefined; date?: undefined; } | { ...; }; }; }' is not assignable to parameter of type 'WithAuth'. Type '{ parent: { database_id: any; type: "database_id"; }; properties: { [x: number]: { title: { text: { content: string; }; }[]; status?: undefined; date?: undefined; } | { status: { name: string; }; title?: undefined; date?: undefined; } | { ...; }; }; }' is not assignable to type '{ parent: { page_id: string; type?: "page_id" | undefined; }; properties: { title?: RichTextItemRequest[] | { title: RichTextItemRequest[]; type?: "title" | undefined; } | undefined; }; icon?: { ...; } | ... 2 more ... | undefined; cover?: { ...; } | ... 1 more ... | undefined; children?: BlockObjectRequest[] | unde...'. Type '{ parent: { database_id: any; type: "database_id"; }; properties: { [x: number]: { title: { text: { content: string; }; }[]; status?: undefined; date?: undefined; } | { status: { name: string; }; title?: undefined; date?: undefined; } | { ...; }; }; }' is not assignable to type '{ parent: { page_id: string; type?: "page_id" | undefined; }; properties: { title?: RichTextItemRequest[] | { title: RichTextItemRequest[]; type?: "title" | undefined; } | undefined; }; icon?: { ...; } | ... 2 more ... | undefined; cover?: { ...; } | ... 1 more ... | undefined; children?: BlockObjectRequest[] | unde...'.

The main type definition here, from Notion's JavaScript SDK, is CreatePageBodyParameters, which includes DateRequest. DateRequest is defined here.

Strangely, if I change the parent type to page_id or delete the definition for page_id from CreatePageBodyParameters, I don't get a type error.

0

There are 0 best solutions below