Skip to content

Invalid declaration emit for conditional type with 'infer' #22755

Closed
@yortus

Description

@yortus

TypeScript Version: 2.8.0-rc

Search Terms: "invalid declaration emit", "declaration infer"

Code

// ========== tsc input ==========
// index.ts
// @declaration: true
export declare function foo<T>(obj: T): T extends () => infer P ? P : never;
export function bar<T>(obj: T) {
    return foo(obj);
}

// ========== tsc output ==========
// index.d.ts
export declare function foo<T>(obj: T): T extends () => infer P ? P : never;
export declare function bar<T>(obj: T): T extends () => P ? P : never;

Expected behavior:
In the emitted declaration file, foo and bar should have equivalent return type annotations.

Actual behavior:
The return type annotation for bar is missing the infer keyword, making the declaration invalid. Any TypeScript project consuming this declaration file will produce the error "Cannot find name 'P'".

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions