Verifying Library Type Exports
What you'll learn: How to ensure your published .d.ts files actually export the types users need and provide proper IntelliSense when they import your library.
When you build a TypeScript library with emitDeclarationOnly, you generate .d.ts declaration files that describe your library's types. But here's the catch: just because TypeScript creates these files doesn't mean they're exporting what you think they are.
Why Verification Matters
Think of your declaration files like a restaurant menu. You can print a beautiful menu, but if the dishes listed don't match what's in the kitchen, customers won't get what they expect. Similarly, your .d.ts files might accidentally hide types, export internal implementation details, or fail to provide autocomplete where users need it.
Verification ensures:
- Public types are actually exported and importable
- Private implementation types stay hidden
- IntelliSense shows the right suggestions
- Breaking changes are caught before publishing
What to Verify
Check that your declaration files include:
- All public API types - interfaces, type aliases, classes you intend users to import
- Correct export statements - types appear with proper
exportkeywords - No accidental internal leaks - implementation details aren't exposed
- Proper module structure - exports match your runtime exports
Manual Verification Approach
Create a separate test TypeScript file that imports from your built package and attempts to use the types exactly as a consumer would. If TypeScript can't find the types or IntelliSense fails, your declarations need fixing.
Automated Testing Pattern
Include a test file in your build pipeline that imports and uses your library's types. If this file type-checks successfully with tsc --noEmit, your type exports work correctly.
Key Takeaway: Generating .d.ts files isn't enough—you must verify they export the right types by testing them as your users would, ensuring proper IntelliSense and type safety in consuming projects.