0

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.

Alex S
  • 190
  • 3
  • 15
  • My solution in the end was to rebuild the type definition by extracting the definitions that I needed and leaving out the rest, including the page_id parent definition, like this https://gist.github.com/AlexIsMaking/24e4618ea41077c75938b20da146e3e8. But obviously that's going to need maintaining so not ideal. – Alex S Jul 02 '23 at 11:27

0 Answers0