Skip to content

Export PageData, PageInfo, and param types from package entry point #227

@bcomnes

Description

@bcomnes

This issue was originally identified in voxpelli/voxpelli.github.com#32

Problem

The main @domstack/static package exports function types (LayoutFunction, TemplateFunction, GlobalDataFunction, PageFunction, etc.) but does not export the data types those functions receive: PageData, PageInfo, TemplateInfo, or any of the *Params types.

Every user-authored customization point in DomStack -- layouts, templates, global.data.js, page functions -- receives PageData objects. The function types are exported, but the objects they operate on are not, leaving a critical gap in the type surface. Users who want full type safety and IDE autocompletion for params, properties, and nested objects like pageInfo have no first-class path to get it.

Current behavior

The entry point at index.d.ts re-exports only function types and the DomStack class. The following are not exported from the entry point:

  • PageData (lib/build-pages/page-data.d.ts)
  • PageInfo (lib/identify-pages.d.ts)
  • TemplateInfo (lib/identify-pages.d.ts)
  • LayoutFunctionParams (lib/build-pages/page-data.d.ts)
  • GlobalDataFunctionParams (lib/build-pages/index.d.ts)
  • PageFunctionParams (lib/build-pages/page-builders/page-writer.d.ts)
  • TemplateFunctionParams (lib/build-pages/page-builders/template-builder.d.ts)

Expected behavior

All types that appear in user-authored function signatures should be importable from the package entry point, so users get full autocompletion and type checking without reaching into internal paths.

Workaround

Users must write verbose, fragile, hand-rolled JSDoc types. This is exactly what real-world global.data.js files do today — with incomplete inline type annotations that miss pageInfo.type, pageInfo.draft, pageInfo.outputName, and more.

Proposed solution

Add re-exports to index.d.ts:

// Data types users interact with
export type { PageData } from './lib/build-pages/page-data.js';
export type { PageInfo, TemplateInfo } from './lib/identify-pages.js';

// Param types for user-authored functions
export type { GlobalDataFunctionParams } from './lib/build-pages/index.js';
export type { LayoutFunctionParams } from './lib/build-pages/page-data.js';
export type { PageFunctionParams } from './lib/build-pages/page-builders/page-writer.js';
export type { TemplateFunctionParams } from './lib/build-pages/page-builders/template-builder.js';

This unlocks clean, complete typing for every customization point:

import type { GlobalDataFunction, PageData, PageInfo } from '@domstack/static';

const globalData: GlobalDataFunction = ({ pages }) => {
  const post: PageData<Record<string, any>> = pages[0];
  const info: PageInfo = post.pageInfo;
  return { posts: pages.map(p => p.vars.title) };
};
export default globalData;

Re-exporting is the standard approach used by most typed packages and carries no runtime cost since these are type-only exports.

Alternatives considered

Approach Pros Cons
Re-export from index (proposed) Zero breaking changes, immediate DX win Slightly larger public API surface
Document deep import paths No code changes Fragile -- internal paths may change between versions
Generate a standalone .d.ts barrel Clean separation Extra build step, maintenance overhead

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions