Skip to Content
가이드TypeScript

TypeScript

모든 패키지가 TypeScript로 작성되어 있으며 타입을 export합니다.

타입 import

import type { NotionBlock } from 'notion-to-jsx'; import type { TocStyleOptions } from 'notion-to-jsx';

또는 notion-to-utils에서:

import type { NotionBlock } from 'notion-to-utils';

블록 타입

NotionBlock은 모든 지원 블록 인터페이스의 유니온 타입입니다:

type NotionBlock = | ParagraphBlock | Heading1Block | Heading2Block | Heading3Block | CodeBlock | ImageBlock | BookmarkBlock | TableBlock | TableRowBlock | QuoteBlock | ToggleBlock | BulletedListItemBlock | NumberedListItemBlock | ColumnListBlock | ColumnBlock | VideoBlock | EmbedBlock | LinkPreviewBlock;

주요 인터페이스

RichTextItem

interface RichTextItem { type: 'text' | 'mention' | 'equation'; plain_text: string; href: string | null; annotations: { bold: boolean; italic: boolean; strikethrough: boolean; underline: boolean; code: boolean; color: NotionColor; }; }

ImageFormatMetadata

getPageBlocks()가 이미지 프로빙을 통해 자동으로 주입하는 메타데이터입니다. 값은 Notion에 표시되는 크기가 아닌 이미지 원본 크기입니다.

interface ImageFormatMetadata { block_width: number; block_height: number; block_aspect_ratio: number; }

OpenGraphData

interface OpenGraphData { title: string; description: string; image: string; siteName: string; url: string; favicon?: string; }

Notion SDK 타입 re-export

notion-to-utils@notionhq/client에서 자주 사용하는 타입을 re-export합니다. 별도로 설치할 필요가 없습니다:

import type { PageObjectResponse, SelectPropertyItemObjectResponse, MultiSelectPropertyItemObjectResponse, GetPageResponse, } from 'notion-to-utils';

타입 내로잉

type 필드를 사용하여 블록 타입을 좁힐 수 있습니다:

function getBlockText(block: NotionBlock): string { if (block.type === 'paragraph') { return block.paragraph.rich_text.map(rt => rt.plain_text).join(''); } if (block.type === 'heading_1') { return block.heading_1.rich_text.map(rt => rt.plain_text).join(''); } return ''; }
Last updated on