Remove undefined from source type of renaming destructuring assignment with default (#41042)

* Remove undefined from source type of destructuring assignment with renaming

* add a test

* add test case from original issue

* add test with undefined default value

* add more test cases with const declaration
This commit is contained in:
uhyo
2022-06-02 07:34:37 +09:00
committed by GitHub
parent 1beb1037c0
commit f3d57ccea8
6 changed files with 324 additions and 0 deletions

View File

@@ -33704,6 +33704,10 @@ namespace ts {
if (target.kind === SyntaxKind.BinaryExpression && (target as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken) {
checkBinaryExpression(target as BinaryExpression, checkMode);
target = (target as BinaryExpression).left;
// A default value is specified, so remove undefined from the final type.
if (strictNullChecks) {
sourceType = getTypeWithFacts(sourceType, TypeFacts.NEUndefined);
}
}
if (target.kind === SyntaxKind.ObjectLiteralExpression) {
return checkObjectLiteralAssignment(target as ObjectLiteralExpression, sourceType, rightIsThis);