@@ -34515,31 +34515,35 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
34515
34515
}
34516
34516
34517
34517
function checkAssertionWorker(node: JSDocTypeAssertion | AssertionExpression, checkMode: CheckMode | undefined) {
34518
- let type : TypeNode;
34518
+ let typeNode : TypeNode;
34519
34519
let expression: Expression;
34520
34520
switch (node.kind) {
34521
34521
case SyntaxKind.AsExpression:
34522
34522
case SyntaxKind.TypeAssertionExpression:
34523
- type = node.type;
34523
+ typeNode = node.type;
34524
34524
expression = node.expression;
34525
34525
break;
34526
34526
case SyntaxKind.ParenthesizedExpression:
34527
- type = getJSDocTypeAssertionType(node);
34527
+ typeNode = getJSDocTypeAssertionType(node);
34528
34528
expression = node.expression;
34529
34529
break;
34530
34530
}
34531
34531
const exprType = checkExpression(expression, checkMode);
34532
- if (isConstTypeReference(type )) {
34532
+ if (isConstTypeReference(typeNode )) {
34533
34533
if (!isValidConstAssertionArgument(expression)) {
34534
34534
error(expression, Diagnostics.A_const_assertions_can_only_be_applied_to_references_to_enum_members_or_string_number_boolean_array_or_object_literals);
34535
34535
}
34536
34536
return getRegularTypeOfLiteralType(exprType);
34537
34537
}
34538
- const links = getNodeLinks(node);
34539
- links.assertionExpressionType = exprType;
34540
- checkSourceElement(type);
34541
- checkNodeDeferred(node);
34542
- return getTypeFromTypeNode(type);
34538
+ checkSourceElement(typeNode);
34539
+ const type = getTypeFromTypeNode(typeNode);
34540
+ // See if we need to check whether the expression and asserted types are comparable.
34541
+ if (!isErrorType(type) && !((exprType.flags | type.flags) & (TypeFlags.AnyOrUnknown | TypeFlags.Never))) {
34542
+ const links = getNodeLinks(node);
34543
+ links.assertionExpressionType = exprType;
34544
+ checkNodeDeferred(node);
34545
+ }
34546
+ return type;
34543
34547
}
34544
34548
34545
34549
function checkAssertionDeferred(node: JSDocTypeAssertion | AssertionExpression) {
@@ -34551,15 +34555,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
34551
34555
Debug.assertIsDefined(links.assertionExpressionType);
34552
34556
const exprType = getRegularTypeOfObjectLiteral(getBaseTypeOfLiteralType(links.assertionExpressionType));
34553
34557
const targetType = getTypeFromTypeNode(type);
34554
- if (!isErrorType(targetType)) {
34555
- addLazyDiagnostic(() => {
34556
- const widenedType = getWidenedType(exprType);
34557
- if (!isTypeComparableTo(targetType, widenedType)) {
34558
- checkTypeComparableTo(exprType, targetType, errNode,
34559
- Diagnostics.Conversion_of_type_0_to_type_1_may_be_a_mistake_because_neither_type_sufficiently_overlaps_with_the_other_If_this_was_intentional_convert_the_expression_to_unknown_first);
34560
- }
34561
- });
34562
- }
34558
+ addLazyDiagnostic(() => {
34559
+ const widenedType = getWidenedType(exprType);
34560
+ if (!isTypeComparableTo(targetType, widenedType)) {
34561
+ checkTypeComparableTo(exprType, targetType, errNode,
34562
+ Diagnostics.Conversion_of_type_0_to_type_1_may_be_a_mistake_because_neither_type_sufficiently_overlaps_with_the_other_If_this_was_intentional_convert_the_expression_to_unknown_first);
34563
+ }
34564
+ });
34563
34565
}
34564
34566
34565
34567
function checkNonNullChain(node: NonNullChain) {
0 commit comments