@@ -1233,7 +1233,7 @@ const enum TypeSystemPropertyName {
1233
1233
ResolvedTypeArguments,
1234
1234
ResolvedBaseTypes,
1235
1235
WriteType,
1236
- IsParameterWithUndefinedInAnnotation ,
1236
+ ParameterInitializerContainsUndefined ,
1237
1237
}
1238
1238
1239
1239
/** @internal */
@@ -9983,8 +9983,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
9983
9983
return !!(target as InterfaceType).baseTypesResolved;
9984
9984
case TypeSystemPropertyName.WriteType:
9985
9985
return !!getSymbolLinks(target as Symbol).writeType;
9986
- case TypeSystemPropertyName.IsParameterWithUndefinedInAnnotation :
9987
- return getNodeLinks(target as VariableDeclaration).isParameterWithUndefinedInAnnotation !== undefined;
9986
+ case TypeSystemPropertyName.ParameterInitializerContainsUndefined :
9987
+ return getNodeLinks(target as ParameterDeclaration).parameterInitializerContainsUndefined !== undefined;
9988
9988
}
9989
9989
return Debug.assertNever(propertyName);
9990
9990
}
@@ -27295,31 +27295,37 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
27295
27295
return symbol.flags & SymbolFlags.Variable && (getDeclarationNodeFlagsFromSymbol(symbol) & NodeFlags.Const) !== 0;
27296
27296
}
27297
27297
27298
- /** remove undefined from the annotated type of a parameter when there is an initializer (that doesn't include undefined) */
27299
- function removeOptionalityFromDeclaredType(declaredType: Type, declaration: VariableLikeDeclaration): Type {
27298
+ function parameterInitializerContainsUndefined(declaration: ParameterDeclaration): boolean {
27300
27299
const links = getNodeLinks(declaration);
27301
27300
27302
- if (links.isParameterWithUndefinedInAnnotation === undefined) {
27303
- if (!pushTypeResolution(declaration, TypeSystemPropertyName.IsParameterWithUndefinedInAnnotation )) {
27301
+ if (links.parameterInitializerContainsUndefined === undefined) {
27302
+ if (!pushTypeResolution(declaration, TypeSystemPropertyName.ParameterInitializerContainsUndefined )) {
27304
27303
reportCircularityError(declaration.symbol);
27305
- return declaredType ;
27304
+ return true ;
27306
27305
}
27307
27306
27308
- const annotationIncludesUndefined = strictNullChecks &&
27309
- declaration.kind === SyntaxKind.Parameter &&
27310
- declaration.initializer &&
27311
- getTypeFacts(declaredType) & TypeFacts.IsUndefined &&
27312
- !(getTypeFacts(checkDeclarationInitializer(declaration, CheckMode.Normal)) & TypeFacts.IsUndefined);
27307
+ const containsUndefined = !!(getTypeFacts(checkDeclarationInitializer(declaration, CheckMode.Normal)) & TypeFacts.IsUndefined);
27313
27308
27314
27309
if (!popTypeResolution()) {
27315
27310
reportCircularityError(declaration.symbol);
27316
- return declaredType ;
27311
+ return true ;
27317
27312
}
27318
27313
27319
- links.isParameterWithUndefinedInAnnotation = !!annotationIncludesUndefined ;
27314
+ links.parameterInitializerContainsUndefined = containsUndefined ;
27320
27315
}
27321
27316
27322
- return links.isParameterWithUndefinedInAnnotation ? getTypeWithFacts(declaredType, TypeFacts.NEUndefined) : declaredType;
27317
+ return links.parameterInitializerContainsUndefined;
27318
+ }
27319
+
27320
+ /** remove undefined from the annotated type of a parameter when there is an initializer (that doesn't include undefined) */
27321
+ function removeOptionalityFromDeclaredType(declaredType: Type, declaration: VariableLikeDeclaration): Type {
27322
+ const removeUndefined = strictNullChecks &&
27323
+ declaration.kind === SyntaxKind.Parameter &&
27324
+ declaration.initializer &&
27325
+ getTypeFacts(declaredType) & TypeFacts.IsUndefined &&
27326
+ !parameterInitializerContainsUndefined(declaration);
27327
+
27328
+ return removeUndefined ? getTypeWithFacts(declaredType, TypeFacts.NEUndefined) : declaredType;
27323
27329
}
27324
27330
27325
27331
function isConstraintPosition(type: Type, node: Node) {
0 commit comments