Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api-extractor] Can not rollup DTS importing from index file #5018

Open
Timeless0911 opened this issue Nov 26, 2024 · 0 comments
Open

[api-extractor] Can not rollup DTS importing from index file #5018

Timeless0911 opened this issue Nov 26, 2024 · 0 comments

Comments

@Timeless0911
Copy link

Timeless0911 commented Nov 26, 2024

Summary

When using dtsRollup feature, I found that it is unable to bundle types from importing from a index file but not write the full path.

Repro steps

https://github.com/Timeless0911/api-extractor-issue-index-path

  1. pnpm install
  2. pnpm build

Expected result:

see https://github.com/Timeless0911/api-extractor-issue-index-path/blob/main/dist-expected/index.d.ts

Actual result:

see https://github.com/Timeless0911/api-extractor-issue-index-path/blob/main/dist-actual/index.d.ts

Details

type-fest is a npm package which has a collection of essential TypeScript types that has below file structure:

.
├── index.d.ts
├── package.json
└── source
    ├── ...
    ├── delimiter-case.d.ts
    ├── internal
    │   ├── ...
    │   └── index.d.ts
    └── ...

This repro demo import KebabCase from type-fest

// src/index.ts
import type { KebabCase } from "type-fest";

export function kebabCase<T extends string>(str: T): KebabCase<T> {
  return str as KebabCase<T>;
}

The KebabCase type is from source/kebab-case.d.ts which have an import from ./delimiter-case

// source/kebab-case.d.ts
import type {DelimiterCase} from './delimiter-case';

// ....

export type KebabCase<Value> = DelimiterCase<Value, '-'>;

In source/delimiter-case.d.ts file, it import some types from ./internal which should be resolved to ./internal/index.d.ts

// source/delimiter-case.d.ts
import type {UpperCaseCharacters, WordSeparators} from './internal';

The actual result keeps these import from ./internal

import type { UpperCaseCharacters } from './internal';
import type { WordSeparators } from './internal';

I modify the source/delimiter-case.d.ts file to write full path of the importer like below, it works as expected.

- import type {UpperCaseCharacters, WordSeparators} from './internal';
+ import type {UpperCaseCharacters, WordSeparators} from './internal/index';

Since both Node.js and Typescript support index file resolution, I think ./internal should be resolved correctly when rolluping DTS.

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/api-extractor version? 7.47.11
Operating system? Mac
API Extractor scenario? rollups (.d.ts)
Would you consider contributing a PR? No
TypeScript compiler version? 5.4.2
Node.js version (node -v)? 22.10.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: AE/AD
Development

No branches or pull requests

1 participant