@@ -4842,8 +4842,6 @@ namespace ts {
4842
4842
4843
4843
function getDefaultOfTypeParameter(typeParameter: TypeParameter): Type {
4844
4844
return hasNonCircularDefault(typeParameter) ? getDefaultFromTypeParameter(typeParameter) : undefined;
4845
- // const defaultType = getResolvedDefault(typeParameter);
4846
- // return defaultType !== noConstraintOrDefaultType && defaultType !== circularConstraintOrDefaultType ? defaultType : undefined;
4847
4845
}
4848
4846
4849
4847
function hasNonCircularDefault(type: TypeParameter) {
@@ -4870,11 +4868,9 @@ namespace ts {
4870
4868
return getResolvedDefault(<TypeParameter>type);
4871
4869
}
4872
4870
if (type.flags & TypeFlags.UnionOrIntersection) {
4873
- const types = (<UnionOrIntersectionType>type).types;
4874
- const defaultTypes = filter(map(types, getResolvedDefaultWorker), x => x !== circularConstraintOrDefaultType);
4875
- return type.flags & TypeFlags.Union && defaultTypes.length === types.length ? getUnionType(defaultTypes) :
4876
- type.flags & TypeFlags.Intersection && defaultTypes.length ? getIntersectionType(defaultTypes) :
4877
- undefined;
4871
+ const types = map((<UnionOrIntersectionType>type).types, getResolvedDefaultWorker);
4872
+ return some(types, x => x === circularConstraintOrDefaultType) ? circularConstraintOrDefaultType :
4873
+ type.flags & TypeFlags.Union ? getUnionType(types) : getIntersectionType(types);
4878
4874
}
4879
4875
return type;
4880
4876
}
@@ -5178,30 +5174,28 @@ namespace ts {
5178
5174
}
5179
5175
5180
5176
function fillMissingTypeArguments(typeArguments: Type[] | undefined, typeParameters: TypeParameter[] | undefined, minTypeArgumentCount: number) {
5181
- const numTypeArguments = typeArguments ? typeArguments.length : 0;
5182
5177
const numTypeParameters = typeParameters ? typeParameters.length : 0;
5183
- if (numTypeArguments >= minTypeArgumentCount && numTypeArguments <= numTypeParameters) {
5184
- if (numTypeParameters) {
5178
+ if (numTypeParameters) {
5179
+ const numTypeArguments = typeArguments ? typeArguments.length : 0;
5180
+ if (numTypeArguments >= minTypeArgumentCount && numTypeArguments <= numTypeParameters) {
5185
5181
if (!typeArguments) {
5186
5182
typeArguments = [];
5187
5183
}
5184
+
5185
+ // Map an unsatisfied type parameter with a default type to the default type.
5186
+ // If a type parameter does not have a default type, or if the default type
5187
+ // is a circular reference, the empty object type is used.
5188
5188
const mapper: TypeMapper = t => {
5189
- for (let i = 0; i < numTypeParameters; i++) {
5190
- if (t === typeParameters[i]) {
5191
- if (!typeArguments[i]) {
5192
- typeArguments[i] = emptyObjectType;
5193
- const defaultType = getDefaultOfTypeParameter(typeParameters[i]);
5194
- if (defaultType) {
5195
- typeArguments[i] = instantiateType(defaultType, mapper);
5196
- }
5197
- }
5198
- return typeArguments[i];
5199
- }
5200
- }
5201
- return t;
5189
+ const i = indexOf(typeParameters, t);
5190
+ return i >= 0
5191
+ ? typeArguments[i] || (typeArguments[i] =
5192
+ instantiateType(getDefaultOfTypeParameter(typeParameters[i]), mapper) ||
5193
+ emptyObjectType)
5194
+ : t;
5202
5195
};
5196
+
5203
5197
for (let i = numTypeArguments; i < numTypeParameters; i++) {
5204
- typeArguments[i] = instantiateType(typeParameters[i], mapper);
5198
+ instantiateType(typeParameters[i], mapper);
5205
5199
}
5206
5200
}
5207
5201
}
0 commit comments