Merge pull request #21610 from Microsoft/fixSharedTypeParameters

Fix unintended sharing of type parameters
This commit is contained in:
Anders Hejlsberg
2018-02-05 11:20:34 -08:00
committed by GitHub
6 changed files with 118 additions and 2 deletions

View File

@@ -8705,7 +8705,7 @@ namespace ts {
const target = type.objectFlags & ObjectFlags.Instantiated ? type.target : type;
const symbol = target.symbol;
const links = getSymbolLinks(symbol);
let typeParameters = links.typeParameters;
let typeParameters = links.outerTypeParameters;
if (!typeParameters) {
// The first time an anonymous type is instantiated we compute and store a list of the type
// parameters that are in scope (and therefore potentially referenced). For type literals that
@@ -8716,7 +8716,7 @@ namespace ts {
typeParameters = symbol.flags & SymbolFlags.TypeLiteral && !target.aliasTypeArguments ?
filter(outerTypeParameters, tp => isTypeParameterPossiblyReferenced(tp, declaration)) :
outerTypeParameters;
links.typeParameters = typeParameters;
links.outerTypeParameters = typeParameters;
if (typeParameters.length) {
links.instantiations = createMap<Type>();
links.instantiations.set(getTypeListId(typeParameters), target);

View File

@@ -3312,6 +3312,7 @@ namespace ts {
type?: Type; // Type of value symbol
declaredType?: Type; // Type of class, interface, enum, type alias, or type parameter
typeParameters?: TypeParameter[]; // Type parameters of type alias (undefined if non-generic)
outerTypeParameters?: TypeParameter[]; // Outer type parameters of anonymous object type
inferredClassType?: Type; // Type of an inferred ES5 class
instantiations?: Map<Type>; // Instantiations of generic type alias (undefined if non-generic)
mapper?: TypeMapper; // Type mapper for instantiation alias