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

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

Closed
yortus opened this issue Mar 21, 2018 · 3 comments
Closed

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

yortus opened this issue Mar 21, 2018 · 3 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@yortus
Copy link
Contributor

yortus commented Mar 21, 2018

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:

@yortus
Copy link
Contributor Author

yortus commented Mar 21, 2018

@weswigham would #22368 fix this?

@weswigham
Copy link
Member

It might, by chance, because I introduced an actual InferType type kind in that PR so I could distinguish the infer location from the use locations for type parameter lists.

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Mar 21, 2018
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 2.8.1 milestone Mar 21, 2018
@DanielRosenwasser
Copy link
Member

Let's get a fix specifically for this first if we can, and then use #22368 if that gets pulled in.

@ahejlsberg ahejlsberg assigned ahejlsberg and unassigned weswigham Mar 21, 2018
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Mar 21, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants