Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
¿Cómo obtener "to_do" de un bloque de nociones usando mecanografiado?

Recientemente probé la versión final de Notion API. Usando mecanografiado, hice una solicitud de niños de bloque de recuperación:

 (async () => { const blockId = process.env.BLOCK_ID; const response = await notion.blocks.children.list({ block_id: blockId, page_size: 50, }); console.log(response.results[1].to_do); })();

Mensaje de error

Por alguna razón, mecanografiado me dice que to_do no existe en el tipo (PartialBlockObjectResponse | BlockObjectResponse) . Miré la definición de tipo y... estaba allí:

 declare type BlockObjectResponse = { // ... { type: "to_do"; to_do: { rich_text: Array<RichTextItemResponse>; color: ApiColor; checked: boolean; }; object: "block"; id: string; created_time: string; created_by: { id: IdRequest; object: "user"; }; last_edited_time: string; last_edited_by: { id: IdRequest; object: "user"; }; has_children: boolean; archived: boolean; } // ... }

Intenté hacer type guard

 function isToDo(value: PartialBlockObjectResponse | BlockObjectResponse): value is BlockObjectResponse { return "to_do" in value; } /* Error: TS2304: Cannot find name 'PartialBlockObjectResponse'. */

e importar el tipo desde el paquete

 import type {PartialBlockObjectResponse} from "@notionhq/client/build/src/api-endpoints"; // Error: Module '"@notionhq/client/build/src/api-endpoints"' declares 'PartialBlockObjectResponse' locally, but it is not exported.

Ninguno ayudó.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

(Frustrante) Ese paquete no exporta sus tipos . Hay un problema abierto al respecto en el repositorio.

Pero puede solucionar esto usando un genérico con su función de predicado:

Parque infantil TS

 import {Client} from '@notionhq/client'; declare const notion: Client; declare const blockId: string; function isTodo <T extends Record<string, unknown>>(obj: T): obj is T & { type: 'to_do' } { return 'type' in obj && obj.type === 'to_do'; } (async () => { const response = await notion.blocks.children.list({block_id: blockId, page_size: 50}); for (const result of response.results) { if (isTodo(result)) { result.to_do; /* ^^^^^ is now this type: { rich_text: RichTextItemResponse[]; color: ApiColor; checked: boolean; } */ } } })()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!