Skip to content

Conversation

@scottlovegrove
Copy link
Contributor

@scottlovegrove scottlovegrove commented Nov 24, 2025

Summary

Fixes #407

This PR resolves the type re-export issue introduced in v6.0.0 (PR #379) where types exported from this package could not be re-exported by consuming packages.

Root Cause

When package.json has "type": "module", TypeScript treats .d.ts files as ESM modules, which require explicit file extensions (.js) for relative imports. The generated declaration files had imports like from './todoist-api' instead of from './todoist-api.js', causing module resolution to fail when other packages tried to re-export types.

Changes

  • Added scripts/fix-dts-imports.cjs: Post-build script that adds .js extensions to all relative imports in generated .d.ts files
    • Handles import statements
    • Handles export statements
    • Handles dynamic import() type expressions
  • Updated package.json:
    • Added build:fix-dts script to run the fixer
    • Updated build script to include the fix-dts step
    • Added attw script for type validation using @arethetypeswrong/cli
      • Ignores fallback-condition and false-esm rules (known limitations of dual-module packages that don't affect functionality)
    • Updated integrity-checks to include attw validation

Verification

Before fix (using @arethetypeswrong/cli --pack):

After fix:

  • InternalResolutionError - FIXED
  • 👺 FalseESM - Known limitation (ignored in CI)
  • 🐛 FallbackCondition - TypeScript bug (ignored in CI)

The critical InternalResolutionError that prevented type re-exports is now resolved. The remaining warnings are expected for dual-module packages and are safely ignored:

  • FalseESM: Types are marked as ESM (due to "type": "module") while CommonJS implementation has its own package.json. This is intentional for dual-module packages.
  • FallbackCondition: TypeScript's handling of the exports field has a known bug where it falls back to the types condition. This doesn't affect runtime behavior.

Test Plan

  • Build completes successfully with new fix-dts step
  • Declaration files now have .js extensions on all relative imports
  • @arethetypeswrong/cli validation passes (no InternalResolutionError)
  • CI includes type validation to prevent future regressions
  • All tests pass

🤖 Generated with Claude Code

scottlovegrove and others added 2 commits November 24, 2025 19:04
…e-export issue

Fixes #407

When package.json has "type": "module", TypeScript treats .d.ts files as ESM modules,
which require explicit file extensions for relative imports. Without these extensions,
type re-exports from consuming packages fail with InternalResolutionError.

Changes:
- Add scripts/fix-dts-imports.cjs to add .js extensions to all relative imports in .d.ts files
- Update build process to run fix-dts step after generating types
- Add @arethetypeswrong/cli validation to integrity-checks to prevent regressions

This resolves the regression introduced in v6.0.0 (PR #379) where dual module support
broke type re-exports in consuming projects.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The FallbackCondition and FalseESM warnings are known limitations of dual-module
packages that don't affect functionality. The critical InternalResolutionError
has been fixed, which was the actual bug.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@scottlovegrove scottlovegrove requested review from a team and nats12 and removed request for a team November 24, 2025 19:14
@scottlovegrove scottlovegrove self-assigned this Nov 24, 2025
@scottlovegrove scottlovegrove merged commit f059ad9 into main Nov 24, 2025
2 checks passed
@scottlovegrove scottlovegrove deleted the scottl/export-types branch November 24, 2025 19:14
scottlovegrove added a commit to Doist/twist-sdk-typescript that referenced this pull request Nov 27, 2025
…e-export issue

Fixes type re-export issue where types exported from this package could not be
re-exported by consuming packages when package.json has "type": "module".

## Root Cause

When `package.json` has `"type": "module"`, TypeScript treats `.d.ts` files as
ESM modules, which require explicit file extensions (`.js`) for relative imports.
The generated declaration files had imports like `from './twist-api'` instead of
`from './twist-api.js'`, causing module resolution to fail when other packages
tried to re-export types.

## Changes

- **Added `scripts/fix-dts-imports.cjs`**: Post-build script that adds `.js`
  extensions to all relative imports in generated `.d.ts` files
  - Handles `import` statements
  - Handles `export` statements
  - Handles dynamic `import()` type expressions
- **Updated `package.json`**:
  - Added `build:fix-dts` script to run the DTS fixer
  - Updated `build` script to include the fix-dts step
  - Added `attw` script for type validation using `@arethetypeswrong/cli`
  - Updated `integrity-checks` to include `attw` validation

## Verification

**Before fix** (using `@arethetypeswrong/cli --pack`):
- ❌ **InternalResolutionError** - Module resolution failed (breaking bug)

**After fix**:
- ✅ **No problems found** - All module resolution working correctly ⭐
- ✅ Declaration files now have `.js` extensions on all relative imports
- ✅ Type validation passes with `@arethetypeswrong/cli`

## Test Plan

- [x] Build completes successfully with new fix-dts step
- [x] Declaration files now have `.js` extensions on all relative imports
- [x] `@arethetypeswrong/cli` validation passes (no problems found)
- [x] All 166 tests pass without modification
- [x] TypeScript compilation succeeds without errors

Applies same fix as:
- Doist/todoist-api-typescript#410

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
scottlovegrove added a commit to Doist/twist-sdk-typescript that referenced this pull request Nov 27, 2025
…e-export issue (#64)

Fixes type re-export issue where types exported from this package could not be
re-exported by consuming packages when package.json has "type": "module".

## Root Cause

When `package.json` has `"type": "module"`, TypeScript treats `.d.ts` files as
ESM modules, which require explicit file extensions (`.js`) for relative imports.
The generated declaration files had imports like `from './twist-api'` instead of
`from './twist-api.js'`, causing module resolution to fail when other packages
tried to re-export types.

## Changes

- **Added `scripts/fix-dts-imports.cjs`**: Post-build script that adds `.js`
  extensions to all relative imports in generated `.d.ts` files
  - Handles `import` statements
  - Handles `export` statements
  - Handles dynamic `import()` type expressions
- **Updated `package.json`**:
  - Added `build:fix-dts` script to run the DTS fixer
  - Updated `build` script to include the fix-dts step
  - Added `attw` script for type validation using `@arethetypeswrong/cli`
  - Updated `integrity-checks` to include `attw` validation

## Verification

**Before fix** (using `@arethetypeswrong/cli --pack`):
- ❌ **InternalResolutionError** - Module resolution failed (breaking bug)

**After fix**:
- ✅ **No problems found** - All module resolution working correctly ⭐
- ✅ Declaration files now have `.js` extensions on all relative imports
- ✅ Type validation passes with `@arethetypeswrong/cli`

## Test Plan

- [x] Build completes successfully with new fix-dts step
- [x] Declaration files now have `.js` extensions on all relative imports
- [x] `@arethetypeswrong/cli` validation passes (no problems found)
- [x] All 166 tests pass without modification
- [x] TypeScript compilation succeeds without errors

Applies same fix as:
- Doist/todoist-api-typescript#410

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6.0.0: Exporting types from this package does not work anymore

2 participants