How can I retrieve the 'to_do' field from a Notion block using TypeScript?

Using the final Notion API with TypeScript, fetching block children causes a TS error: the ‘to_do’ field isn’t recognized. How can I fix this?

async function fetchTask() {
  const myId = 'example-id';
  const data = await customClient.getChildren({ id: myId, limit: 50 });
  console.log(data[1].taskItem);
}

try typecasting the block as any so ts can see the to_do field; this hack overcomes strict typing issues. hope it helps, cheers

i ended up parsing the raw json to extract the to_do key instead of relying on strict types. this lets me bypass ts whining without resorting to any casting. works well in my prject for simple integrations.

I encountered a similar issue when developing my own Notion API integration. The solution that worked best for me was to define type guards that check if the block is of the expected type before accessing the ‘to_do’ field. This allows me to narrow the type and safely reference the field without resorting to a catch-all any type. I also updated my local interface definitions to include the ‘to_do’ property as an optional field. This approach not only resolves the TypeScript error, but also improves the robustness of my code by ensuring type integrity.

I resolved a similar issue by extending the default Notion types rather than relying on casting to any. I created a custom interface that includes the to_do field and then used module augmentation to merge my changes with the built-in types. This approach maintains type safety while acknowledging the API’s dynamic structure. It required updating some local type declarations, but it provided a more robust solution and improved autocomplete support in my IDE, thus making the integration cleaner and easier to maintain over time.