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] typesVersions field does't work when rollup DTS #5017

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

[api-extractor] typesVersions field does't work when rollup DTS #5017

Timeless0911 opened this issue Nov 25, 2024 · 0 comments

Comments

@Timeless0911
Copy link

Timeless0911 commented Nov 25, 2024

Summary

When using dtsRollup feature, I found that it is unable to bundle types from dependency while importing from root but works for sub-path modules.

import { ClientDefinition } from 'kit/node';

export declare interface Foo extends ClientDefinition {
    bar: string;
}

export declare const foo: Foo;

export { }

Repro steps

https://github.com/Timeless0911/api-extractor-issue-typeversions

  1. pnpm install
  2. pnpm build

Expected result:

ClientDefinition should be bundled

declare interface ClientDefinition {
    name: string;
}

export declare interface Foo extends ClientDefinition {
    bar: string;
}

export declare const foo: Foo;

export { }

Actual result:

ClientDefinition are not be bundled

import { ClientDefinition } from 'kit/node';

export declare interface Foo extends ClientDefinition {
    bar: string;
}

export declare const foo: Foo;

export { }

Details

If I import ClientDefinition from kit instead of kit/node, it works well.

The package.json of kit is:

{
  "name": "kit",
  "version": "1.0.0",
  "types": "./dist/index.d.ts",
  "main": "./dist/index.js",
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "default": "./dist/index.js"
    },
    "./node": {
      "types": "./dist/node.d.ts",
      "default": "./dist/node.js"
    },
    "./package.json": {
      "default": "./package.json"
    }
  },
  "typesVersions": {
    "*": {
      "node": [
        "./dist/node.d.ts"
      ]
    }
  },
  "sideEffects": false
}

The tsconfig of this repro demo is:

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
  },
  "$schema": "https://json.schemastore.org/tsconfig",
  "include": ["src"]
}

It seems api-extractor will take exports into consider, but will not read typeVersions field.

If I change tsconfig.json to set as below, it will work as expected.

{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "nodenext",
  },
  "$schema": "https://json.schemastore.org/tsconfig",
  "include": ["src"]
}

Also, if I change the import path as below, it will also work as expected.

- import { ClientDefinition } from "kit/node";
+ import { ClientDefinition } from "kit";

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