mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Add review suggestions
Move object destructuring assignment to checkObjectLiteralAssignment Only check assignability of types in checkVariableLikeDeclaration for object/array destructuring when there are properties present in the pattern.
This commit is contained in:
@@ -18769,6 +18769,9 @@ namespace ts {
|
||||
|
||||
function checkObjectLiteralAssignment(node: ObjectLiteralExpression, sourceType: Type): Type {
|
||||
const properties = node.properties;
|
||||
if (strictNullChecks && properties.length === 0) {
|
||||
return checkNonNullType(sourceType, node);
|
||||
}
|
||||
for (const p of properties) {
|
||||
checkObjectLiteralDestructuringPropertyAssignment(sourceType, p, properties);
|
||||
}
|
||||
@@ -18908,9 +18911,6 @@ namespace ts {
|
||||
target = (<BinaryExpression>target).left;
|
||||
}
|
||||
if (target.kind === SyntaxKind.ObjectLiteralExpression) {
|
||||
if (strictNullChecks && (<ObjectLiteralExpression>target).properties.length === 0) {
|
||||
return checkNonNullType(sourceType, target);
|
||||
}
|
||||
return checkObjectLiteralAssignment(<ObjectLiteralExpression>target, sourceType);
|
||||
}
|
||||
if (target.kind === SyntaxKind.ArrayLiteralExpression) {
|
||||
@@ -21836,12 +21836,14 @@ namespace ts {
|
||||
if (isBindingPattern(node.name)) {
|
||||
// Don't validate for-in initializer as it is already an error
|
||||
if (node.initializer && node.parent.parent.kind !== SyntaxKind.ForInStatement) {
|
||||
let initializerType = checkExpressionCached(node.initializer);
|
||||
const initializerType = checkExpressionCached(node.initializer);
|
||||
if (strictNullChecks && node.name.elements.length === 0) {
|
||||
initializerType = checkNonNullType(initializerType, node);
|
||||
checkNonNullType(initializerType, node);
|
||||
}
|
||||
else {
|
||||
checkTypeAssignableTo(initializerType, getWidenedTypeForVariableLikeDeclaration(node), node, /*headMessage*/ undefined);
|
||||
checkParameterInitializer(node);
|
||||
}
|
||||
checkTypeAssignableTo(initializerType, getWidenedTypeForVariableLikeDeclaration(node), node, /*headMessage*/ undefined);
|
||||
checkParameterInitializer(node);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user