Skip to content

[api-extractor] improve the .d.ts rollup to handle augmented types #1709

@yangmingshan

Description

@yangmingshan

This issue proposes to improve API Extractor's analysis to handle augmented types, as illustrated in this repro from @manrueda:

https://github.com/manrueda/api-extractor-module-augmentation

In TypeScript, types can get "augmented" when the original declaration is extended locally in a file, via declaration merging. For example, we might have an entry point like this:

index.ts

// imports an interface declaration
import { Extras } from './core';

// adds more members to the interface, but only from the perspective of this file
import './plugin';

// exports the augmented result
export { Extras }

Note: The original issue description involved global variables, but we have narrowed the scope to only consider augmentation of normal exports. Details in this comment.

Original description involving global augmentation

Is this a feature or a bug?

  • Feature
  • Bug

Please describe the actual behavior.
.d.ts rollup generation will remove global type extension.

If the issue is a bug, how can we reproduce it? Please provide detailed steps and include a GitHub branch if applicable. Your issue will get resolved faster if you can make it easy to investigate.
Source code:

declare global {
  namespace jest {
    interface Matchers<R, T> {
      toHaveBeenWarned(): R
      toHaveBeenWarnedLast(): R
      toHaveBeenWarnedTimes(n: number): R
    }
  }
}

export interface User {
  name: string
}

Generated code:

export declare interface User {
  name: string
}

export { }

What is the expected behavior?
Generated code should keep global type extension.

If this is a bug, please provide the tool version, Node.js version, and OS.

  • Tool: api-extractor
  • Tool Version: 7.7.6
  • Node Version: 13.7.0
    • Is this a LTS version? No
    • Have you tested on a LTS version? No
  • OS: macOS Catalina 10.15.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThe issue is asking for a new feature or design changerepro confirmedThe issue comments included repro instructions, and the maintainers reproduced the problem

    Type

    No type

    Projects

    Status

    AE/AD

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions