Skip to content

Fix missing 'infer T' in declaration files #22764

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

Merged
merged 10 commits into from
Mar 21, 2018

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Mar 21, 2018

With this PR we properly emit infer T declarations in representations of instantiated conditional types.

Additionally, we report errors on infer T declarations in invalid locations within conditional types nested within other conditional types. Additionally, we now properly locate the owning conditional type for an infer T declaration: It is the innermost containing conditional type in whose extends type the infer T declaration occurs.

Fixes #22755.

@DanielRosenwasser
Copy link
Member

Let's make sure this gets into release-2.8 after merging.

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export type BadNested<T> = {x: T extends number ? T : string};

export declare function foo<T>(obj: T): T extends {[K in keyof BadNested<infer P>]: BadNested<infer P>[K]} ? P : never;
export function bar<T>(obj: T) {
    return foo(obj);
}

will still emit invalid declarations for bar (but issue no errors), since we happily inline aliases from time-to-time (even though this breaks conditional types under their current scoping rules). The only real fix I see is to make aliases actually inlinable again by allowing infer types in the other conditional type clauses, but correctly scoping them to the outer scope (rather than them being a deadzone like they are with this PR).

@ahejlsberg
Copy link
Member Author

@weswigham Should be good now.

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ahejlsberg ahejlsberg merged commit ee546fb into master Mar 21, 2018
@ahejlsberg ahejlsberg deleted the fixInferTypeDeclarationFiles branch March 21, 2018 21:18
@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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants