Closed
Description
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:
- 'infer' type parameters declarations aren't printed in quick info. #21836 is similar but relates to Quick Info. The sample code there produces a correct declaration emit however.
- WIP - Allow infer types in expression type argument positions #22368 says it fixes 'infer' type parameters declarations aren't printed in quick info. #21836, so maybe it fixes this too?