TypeScript types for core Notion data structures.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Type definitions for Notion databases (collections) including schemas, properties, and data validation. Collections represent structured data with typed properties and validation rules.
Main interface representing a Notion database/collection.
/**
* Database/collection definition
*/
interface Collection {
/** Collection identifier */
id: ID;
/** Collection version */
version: number;
/** Collection name (decorated text) */
name: Decoration[];
/** Property schema definitions */
schema: CollectionPropertySchemaMap;
/** Collection icon */
icon: string;
/** Parent block ID */
parent_id: ID;
/** Parent table type */
parent_table: string;
/** Whether collection is active */
alive: boolean;
/** Source collection if copied */
copied_from: string;
/** Template page IDs */
template_pages?: ID[];
/** Collection formatting */
format?: {
collection_page_properties?: Array<{
property: string;
visible: boolean;
}>;
property_visibility?: Array<{
property: string;
visibility: 'show' | 'hide';
}>;
hide_linked_collection_name?: boolean;
};
}/**
* Schema definition for collection properties
*/
interface CollectionPropertySchema {
/** Property name */
name: string;
/** Property data type */
type: PropertyType;
/** Options for select properties */
options?: SelectOption[];
/** Formatting for number properties */
number_format?: NumberFormat;
/** Formula definition for formula properties */
formula?: Formula;
}
/**
* Map of property schemas
*/
interface CollectionPropertySchemaMap {
[key: string]: CollectionPropertySchema;
}
/**
* Option for select/multi-select properties
*/
interface SelectOption {
/** Option identifier */
id: string;
/** Option color */
color: Color;
/** Option display text */
value: string;
}/**
* Types of structured data supported by Notion collections
*/
type PropertyType =
| 'title' // Title/primary text
| 'text' // Plain text
| 'number' // Numeric values
| 'select' // Single select dropdown
| 'status' // Status property
| 'multi_select' // Multi-select dropdown
| 'auto_increment_id' // Auto-incrementing ID
| 'date' // Date/datetime
| 'person' // User reference
| 'file' // File attachment
| 'checkbox' // Boolean checkbox
| 'url' // URL/link
| 'email' // Email address
| 'phone_number' // Phone number
| 'formula' // Computed formula
| 'relation' // Relation to other collection
| 'created_time' // Creation timestamp
| 'created_by' // Creator user
| 'last_edited_time' // Last edit timestamp
| 'last_edited_by'; // Last editor user/**
* Types of number formatting supported by Notion
*/
type NumberFormat =
// Basic formats
| 'number_with_commas'
| 'percent'
| 'number'
// Major currencies
| 'dollar'
| 'euro'
| 'pound'
| 'yen'
| 'rupee'
| 'won'
| 'yuan'
// Regional currencies
| 'argentine_peso'
| 'baht'
| 'canadian_dollar'
| 'chilean_peso'
| 'colombian_peso'
| 'danish_krone'
| 'dirham'
| 'forint'
| 'franc'
| 'hong_kong_dollar'
| 'koruna'
| 'krona'
| 'leu'
| 'lira'
| 'mexican_peso'
| 'new_taiwan_dollar'
| 'new_zealand_dollar'
| 'norwegian_krone'
| 'philippine_peso'
| 'peruvian_sol'
| 'rand'
| 'real'
| 'ringgit'
| 'riyal'
| 'ruble'
| 'rupiah'
| 'shekel'
| 'singapore_dollar'
| 'uruguayan_peso'
| 'zloty';Usage Examples:
import {
Collection,
CollectionPropertySchema,
PropertyType,
NumberFormat,
SelectOption
} from "notion-types";
// Define select options
const statusOptions: SelectOption[] = [
{ id: "1", color: "green", value: "Active" },
{ id: "2", color: "yellow", value: "Pending" },
{ id: "3", color: "red", value: "Inactive" }
];
// Define property schema
const userSchema: CollectionPropertySchemaMap = {
title: {
name: "Name",
type: "title"
},
email: {
name: "Email",
type: "email"
},
age: {
name: "Age",
type: "number",
number_format: "number"
},
salary: {
name: "Salary",
type: "number",
number_format: "dollar"
},
status: {
name: "Status",
type: "select",
options: statusOptions
},
skills: {
name: "Skills",
type: "multi_select",
options: [
{ id: "js", color: "yellow", value: "JavaScript" },
{ id: "ts", color: "blue", value: "TypeScript" },
{ id: "py", color: "green", value: "Python" }
]
},
active: {
name: "Active",
type: "checkbox"
},
hire_date: {
name: "Hire Date",
type: "date"
},
manager: {
name: "Manager",
type: "person"
},
website: {
name: "Website",
type: "url"
}
};
// Create a collection
const usersCollection: Collection = {
id: "collection-123",
version: 1,
name: [["Users Database"]],
schema: userSchema,
icon: "👥",
parent_id: "page-456",
parent_table: "block",
alive: true,
copied_from: "",
template_pages: [],
format: {
collection_page_properties: [
{ property: "title", visible: true },
{ property: "email", visible: true },
{ property: "status", visible: true }
],
property_visibility: [
{ property: "age", visibility: "show" },
{ property: "salary", visibility: "hide" }
]
}
};
// Type-safe property access
function getPropertyType(collection: Collection, propertyId: string): PropertyType | undefined {
return collection.schema[propertyId]?.type;
}
// Validate property schema
function validateProperty(schema: CollectionPropertySchema): boolean {
if (schema.type === 'select' || schema.type === 'multi_select') {
return Array.isArray(schema.options) && schema.options.length > 0;
}
if (schema.type === 'number') {
return schema.number_format !== undefined;
}
return true;
}Install with Tessl CLI
npx tessl i tessl/npm-notion-types