Skip to content

Add built-in TypeScript type definitions#820

Open
fdb wants to merge 2 commits intomasterfrom
typescript-types
Open

Add built-in TypeScript type definitions#820
fdb wants to merge 2 commits intomasterfrom
typescript-types

Conversation

@fdb
Copy link
Copy Markdown
Contributor

@fdb fdb commented Mar 3, 2026

Summary

Closes #809. Ships .d.ts type definitions inside the npm package so TypeScript users no longer need the separate @types/opentype.js package.

  • Enhances JSDoc annotations in core source files (Font, Glyph, Path, BoundingBox, parse()) and uses tsc --allowJs --declaration --emitDeclarationOnly to generate .d.mts files at build time
  • Adds PathCommand discriminated union (M/L/C/Q/Z) for type-safe command handling, plus typed FontOptions, GlyphRenderOptions, and GlyphOptions interfaces
  • Adds "types" field and "exports" map to package.json for proper TypeScript/bundler resolution
  • Renames tiny-inflate@1.0.3.esm.mjstiny-inflate-1.0.3.esm.mjs (the @ broke TypeScript module resolution)
  • Adds type verification test (test/types/test-types.ts) that exercises the full public API under --strict mode

Test plan

  • npm run build succeeds (UMD + ESM + types generation)
  • npm run test:types passes (strict-mode type verification test)
  • npx mocha --recursive — all 328 tests pass
  • npm run lint passes
  • No runtime behavior changes — only JSDoc annotations and build infrastructure

🤖 Generated with Claude Code

fdb and others added 2 commits March 3, 2026 22:58
Ship .d.ts type definitions inside the npm package so TypeScript users
no longer need the separate @types/opentype.js package. Uses JSDoc
annotations in source files with tsc --allowJs --declaration to generate
.d.mts files at build time.

Core public API types: Font, Glyph, Path, BoundingBox, parse()
- PathCommand discriminated union (M/L/C/Q/Z) for type-safe command handling
- FontOptions, GlyphRenderOptions, GlyphOptions typed interfaces
- All Font/Glyph/Path/BoundingBox methods and properties typed

Infrastructure:
- tsconfig.json for declaration generation
- "b:types" build script integrated into "build"
- package.json "types" field and "exports" map for bundler resolution
- Type verification test (test/types/test-types.ts) with "test:types" script
- Rename tiny-inflate file to remove @ that breaks TS module resolution

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fdb fdb requested a review from Connum March 4, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Built-in TypeScript types

1 participant