Skip to content

[api-extractor] parsing error on (infer T extends U) pattern #3486

Closed
@Jym77

Description

@Jym77

Summary

In microsoft/TypeScript#49517 I reported a TS bug and was given a workaround which, unfortunately seems to break api-extractor 😢

My .d.ts file:

declare class Foo {
    protected foo: number;
}
declare class Bar {
    protected foo: number;
}
declare type Nothing<V extends Foo> = void;
/**
 * @internal
 */
export declare type Broken<V extends Array<Foo | Bar>> = {
    readonly [P in keyof V]: V[P] extends (infer T extends Foo) ? Nothing<T> : never;
};
export {};
//# sourceMappingURL=index.d.ts.map

Running api-extractor, I get the error:

ERROR: Internal Error: Unable to follow symbol for ""
You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.

I assume it is on the (infer T extends Foo) pattern that it breaks, given that it used to work fine on older version of the code that was just using V[P] instead.
Additionally, it seems that prettier also breaks because it expects a ? after the inner extends, so my guess it that api-extractor has a similar problem 🤔

Repro steps

Creating a fresh TS project, install api-extractor with default config (api-extractor init). Use the following TS file:

class Foo {
  protected foo = 0;
}

class Bar {
  protected foo = 0;
}

type Nothing<V extends Foo> = void;

/**
 * @internal
 */
export declare type Broken<V extends Array<Foo | Bar>> = {
  // breaks TS, see https://github.com/microsoft/TypeScript/issues/49517
  // readonly [P in keyof V]: V[P] extends Foo ? Nothing<V[P]> : never;
  
  // workaround, breaks API extractor
  readonly [P in keyof V]: V[P] extends (infer T extends Foo) ? Nothing<T> : never;
};

Run api-extractor --local

Expected result: API is successfully extracted

Actual result:

ERROR: Internal Error: Unable to follow symbol for ""
You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.

Details

Diagnostic:
diagnostic.txt

Standard questions

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

Question Answer
@microsoft/api-extractor version? 7.25.2
Operating system? Windows
API Extractor scenario?
Would you consider contributing a PR? No
TypeScript compiler version? 4.7.4
Node.js version (node -v)? 16.14.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions