ts-library

Guides authoring TypeScript libraries covering package exports, build tooling, API design, testing, and npm publishing.

Updated Aug 16, 2026
One-click install
npx skills add https://github.com/Aveer/skills --skill ts-library-aveer
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: ts-library
Source: https://github.com/Aveer/skills/tree/main/skills/ts-library
Command: npx skills add https://github.com/Aveer/skills --skill ts-library-aveer

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Setting up a TypeScript library involves many interlocking decisions—package.json exports for dual CJS/ESM, tsconfig options, build tool selection, type-safe API design, testing, and release automation—and getting any of them wrong produces broken packages or poor consumer experience. ## Core Features & Use Cases - Project & Build Setup: Covers project scaffolding, pnpm catalogs, tsdown/unbuild configuration, and dual CJS/ESM output with type declarations. - API & Type Design: Provides patterns for options resolution, factory functions, builders, plugins (unplugin), and advanced TypeScript type inference tricks. - Testing & Release: Includes vitest setup, fixture-based and type-level testing, GitHub Actions CI, OIDC-based npm publishing with provenance, and pkg-pr-new PR previews. - Use Case: When creating a new npm package, load the relevant reference files to configure exports, build with tsdown, verify with publint and arethetypeswrong, and set up a tag-triggered OIDC release workflow. ## Quick Start Ask the AI to scaffold a new TypeScript library with dual CJS/ESM exports, tsdown build config, vitest tests, and an OIDC npm release workflow.

Frequently Asked Questions about ts-library

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up package.json exports for dual CJS/ESM?▼

Define an exports map with types, import, and require conditions pointing to .d.mts, .mjs, and .cjs files, keeping types first. Also set main, module, and types as fallbacks, and mark sideEffects as false for tree-shaking.

tsdown vs unbuild: which build tool for a TypeScript library?▼

tsdown is recommended for most libraries because it is fast and simple, with dts generation and glob entries. unbuild suits complex builds, Nuxt modules, and cases needing automatic externals handling.

Should I use moduleResolution Bundler or NodeNext in tsconfig?▼

Use Bundler for libraries consumed by bundlers like Vite or webpack, since it allows extensionless imports and supports the exports field. Use Node16 or NodeNext for Node.js-only libraries requiring explicit .js extensions.

How do I publish to npm from GitHub Actions without an NPM_TOKEN?▼

Use OIDC trusted publishing: grant id-token write permission, run on Node.js 24 or later, add registry-url to setup-node, include a repository field in package.json, and publish with the --provenance flag after configuring the trusted publisher on npmjs.com.

Why does my published package fail type resolution for consumers?▼

Type resolution fails when declaration files are missing, condition order is wrong, or moduleResolution mismatches. Validate the package with publint and @arethetypeswrong/cli, and enable dts generation in your build config.

How do I test TypeScript types across multiple compiler versions?▼

Enable vitest typecheck and write expectTypeOf assertions in test-d files. For multi-version coverage, add a CI matrix that installs typescript at versions like 5.0 through 5.8 and runs typecheck for each.