mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
Detect circularities when removing 'undefined' from defaulted params (#37023)
Fixes #37008 Note that referencing a variable in its initializer is a TDZ error; the OP report had OOB logic that prevented this in practice (?)
This commit is contained in:
@@ -20522,12 +20522,20 @@ namespace ts {
|
||||
|
||||
/** remove undefined from the annotated type of a parameter when there is an initializer (that doesn't include undefined) */
|
||||
function removeOptionalityFromDeclaredType(declaredType: Type, declaration: VariableLikeDeclaration): Type {
|
||||
const annotationIncludesUndefined = strictNullChecks &&
|
||||
declaration.kind === SyntaxKind.Parameter &&
|
||||
declaration.initializer &&
|
||||
getFalsyFlags(declaredType) & TypeFlags.Undefined &&
|
||||
!(getFalsyFlags(checkExpression(declaration.initializer)) & TypeFlags.Undefined);
|
||||
return annotationIncludesUndefined ? getTypeWithFacts(declaredType, TypeFacts.NEUndefined) : declaredType;
|
||||
if (pushTypeResolution(declaration.symbol, TypeSystemPropertyName.DeclaredType)) {
|
||||
const annotationIncludesUndefined = strictNullChecks &&
|
||||
declaration.kind === SyntaxKind.Parameter &&
|
||||
declaration.initializer &&
|
||||
getFalsyFlags(declaredType) & TypeFlags.Undefined &&
|
||||
!(getFalsyFlags(checkExpression(declaration.initializer)) & TypeFlags.Undefined);
|
||||
popTypeResolution();
|
||||
|
||||
return annotationIncludesUndefined ? getTypeWithFacts(declaredType, TypeFacts.NEUndefined) : declaredType;
|
||||
}
|
||||
else {
|
||||
reportCircularityError(declaration.symbol);
|
||||
return declaredType;
|
||||
}
|
||||
}
|
||||
|
||||
function isConstraintPosition(node: Node) {
|
||||
|
||||
Reference in New Issue
Block a user