Skip to content

Fix anonymous type instantiation #19091

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 6 commits into from
Oct 11, 2017
Merged

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Oct 11, 2017

With #18231 we included an optimization to track which type parameters are referenced in anonymous types such that unnecessary instantiations can be avoided. This optimization did not properly account for locally declared types that might reference type parameters. With this PR we now optimize only when there are no intervening statement blocks between an anonymous type literal and a particular type parameter (and thus no opportunity to indirectly reference the type parameter), and no type queries (typeof in a type position) within the anonymous type literal.

Fixes #19043.

@ahejlsberg ahejlsberg requested a review from mhegazy October 11, 2017 00:54
@mhegazy
Copy link
Contributor

mhegazy commented Oct 11, 2017

here is another example using typeof that exhibits the same aliasing behavior like type aliases:

declare function f<T>(a: T, b: { a: typeof a });
f(2, { a: 2 });

@ahejlsberg ahejlsberg merged commit 728d2a9 into master Oct 11, 2017
@ahejlsberg ahejlsberg deleted the fixAnonymousTypeInstantiation branch October 11, 2017 23:54
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 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.

2 participants