ts-library

Guides authoring TypeScript libraries with dual CJS/ESM builds, exports, testing, and npm publishing.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Setting up a TypeScript library involves many error-prone decisions: package.json exports for dual CJS/ESM output, tsconfig options, build tool selection, type declaration generation, testing, and npm release workflows. This Skill consolidates proven patterns from projects like unocss, shiki, unplugin, vite, vitest, vueuse, zod, trpc, and drizzle-orm into on-demand reference guides. ## Core Features & Use Cases - Project & Build Setup: Covers project scaffolding (single package or pnpm monorepo with catalogs), package.json exports for dual CJS/ESM, tsconfig configuration, and build tooling with tsdown or unbuild. - API & Type Design: Provides patterns for options resolution, factory functions, builders, plugins (unplugin), lazy getters, plus advanced TypeScript type patterns like brand types, module augmentation, and type accumulation. - Testing & Release: Guides vitest setup (fixtures, type-level tests, coverage), ESLint via @antfu/eslint-config, GitHub Actions CI, OIDC-based npm publishing with provenance, and pkg-pr-new PR previews. - Use Case: You are starting a new npm package and need correct exports, a tsdown build producing .mjs/.cjs/.d.ts, vitest tests, and a tag-triggered OIDC release workflow—load only the relevant reference files for each step. ## Quick Start Ask the AI to set up a new TypeScript library with dual CJS/ESM exports, a tsdown build, vitest tests, and an 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 output?▼

Define an exports map with types, import, and require conditions pointing to .d.mts, .mjs, and .cjs files, and keep main, module, and types as fallbacks. Set "type": "module" and "sideEffects": false for tree-shaking, then validate with publint and @arethetypeswrong/cli.

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

Use tsdown for most libraries since it is fast and simple, with entry, format, and dts options. Choose unbuild for complex builds, Nuxt modules, or when you need automatic externals handling.

What tsconfig settings are recommended for library development?▼

Use target and module set to ESNext, moduleResolution set to Bundler, strict mode, noEmit, isolatedDeclarations, and verbatimModuleSyntax. Use Node16 or NodeNext resolution only for Node.js-only libraries.

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, and publish with the --provenance flag. Configure the package as a trusted publisher in npm settings and include a repository field in package.json.

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

Common causes are missing types conditions in exports, wrong declaration file extensions, or mismatched moduleResolution. Run publint and @arethetypeswrong/cli --pack . in CI to detect these issues before publishing.

How do I test TypeScript types with vitest?▼

Enable typecheck in the vitest config and write .test-d.ts files using expectTypeOf assertions. You can also matrix-test across multiple TypeScript versions in CI to catch compatibility regressions.