mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Better checking of assignment declarations (#28387)
Previously, type checking was turned off for all assignment declarations. This is a problem when the declarations are annotated with jsdoc types. This PR checks assignment declarations, *except* for expando initialisers. Expando initialisers are 1. Empty object types. 2. Function types. 3. Class types. 4. Non-empty object types when the assignment declaration kind is prototype assignment or module.exports assignment.
This commit is contained in:
committed by
GitHub
parent
7a7328a17f
commit
53bb4e84a2
@@ -22321,8 +22321,17 @@ namespace ts {
|
||||
leftType;
|
||||
case SyntaxKind.EqualsToken:
|
||||
const declKind = isBinaryExpression(left.parent) ? getAssignmentDeclarationKind(left.parent) : AssignmentDeclarationKind.None;
|
||||
checkAssignmentDeclaration(declKind, right);
|
||||
checkAssignmentDeclaration(declKind, rightType);
|
||||
if (isAssignmentDeclaration(declKind)) {
|
||||
if (!(rightType.flags & TypeFlags.Object) ||
|
||||
declKind !== AssignmentDeclarationKind.ModuleExports &&
|
||||
declKind !== AssignmentDeclarationKind.Prototype &&
|
||||
!isEmptyObjectType(rightType) &&
|
||||
!isFunctionObjectType(rightType as ObjectType) &&
|
||||
!(getObjectFlags(rightType) & ObjectFlags.Class)) {
|
||||
// don't check assignability of module.exports=, C.prototype=, or expando types because they will necessarily be incomplete
|
||||
checkAssignmentOperator(rightType);
|
||||
}
|
||||
return leftType;
|
||||
}
|
||||
else {
|
||||
@@ -22339,9 +22348,8 @@ namespace ts {
|
||||
return Debug.fail();
|
||||
}
|
||||
|
||||
function checkAssignmentDeclaration(kind: AssignmentDeclarationKind, right: Expression) {
|
||||
function checkAssignmentDeclaration(kind: AssignmentDeclarationKind, rightType: Type) {
|
||||
if (kind === AssignmentDeclarationKind.ModuleExports) {
|
||||
const rightType = checkExpression(right, checkMode);
|
||||
for (const prop of getPropertiesOfObjectType(rightType)) {
|
||||
const propType = getTypeOfSymbol(prop);
|
||||
if (propType.symbol && propType.symbol.flags & SymbolFlags.Class) {
|
||||
|
||||
Reference in New Issue
Block a user