Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2328,7 +2328,7 @@ func (c *Checker) checkDeferredNode(node *ast.Node) {
c.checkJsxSelfClosingElementDeferred(node)
case ast.KindJsxElement:
c.checkJsxElementDeferred(node)
case ast.KindTypeAssertionExpression, ast.KindAsExpression, ast.KindParenthesizedExpression:
case ast.KindTypeAssertionExpression, ast.KindAsExpression:
c.checkAssertionDeferred(node)
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of ast.KindParenthesizedExpression from this case statement appears unrelated to the main PR purpose of fixing insufficient type overlap diagnostics. This change should be explained or moved to a separate commit to maintain clear separation of concerns.

Suggested change
c.checkAssertionDeferred(node)
c.checkAssertionDeferred(node)
case ast.KindParenthesizedExpression:
c.checkExpression(node.AsParenthesizedExpression().Expression)

Copilot uses AI. Check for mistakes.

case ast.KindVoidExpression:
c.checkExpression(node.AsVoidExpression().Expression)
Expand Down Expand Up @@ -11799,7 +11799,11 @@ func (c *Checker) checkAssertionDeferred(node *ast.Node) {
if !c.isErrorType(targetType) {
widenedType := c.getWidenedType(exprType)
if !c.isTypeComparableTo(targetType, widenedType) {
c.checkTypeComparableTo(exprType, targetType, node, 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)
errNode := node
if node.Flags&ast.NodeFlagsReparsed != 0 {
errNode = node.Type()
}
c.checkTypeComparableTo(exprType, targetType, errNode, 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)
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions internal/checker/relater.go
Original file line number Diff line number Diff line change
Expand Up @@ -4728,16 +4728,16 @@ func (r *Relater) reportRelationError(message *diagnostics.Message, source *Type
return
}
// Suppress if next message is a missing property message for source and target and we're not
// reporting on interface implementation
// reporting on conversion or interface implementation
case diagnostics.Property_0_is_missing_in_type_1_but_required_in_type_2:
if !isInterfaceImplementationMessage(message) && r.chainArgsMatch(nil, generalizedSourceType, targetType) {
if !isConversionOrInterfaceImplementationMessage(message) && r.chainArgsMatch(nil, generalizedSourceType, targetType) {
return
}
// Suppress if next message is a missing property message for source and target and we're not
// reporting on interface implementation
// reporting on conversion or interface implementation
case diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2_and_3_more,
diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2:
if !isInterfaceImplementationMessage(message) && r.chainArgsMatch(generalizedSourceType, targetType) {
if !isConversionOrInterfaceImplementationMessage(message) && r.chainArgsMatch(generalizedSourceType, targetType) {
return
}
}
Expand Down Expand Up @@ -4847,9 +4847,10 @@ func getPropertyNameArg(arg any) string {
return s
}

func isInterfaceImplementationMessage(message *diagnostics.Message) bool {
func isConversionOrInterfaceImplementationMessage(message *diagnostics.Message) bool {
return message == diagnostics.Class_0_incorrectly_implements_interface_1 ||
message == diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass
message == diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass ||
message == 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
}

func chainDepth(chain *ErrorChain) int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ fuzzy.ts(13,18): error TS2420: Class 'C' incorrectly implements interface 'I'.
Property 'alsoWorks' is missing in type 'C' but required in type 'I'.
fuzzy.ts(21,34): error TS2322: Type 'this' is not assignable to type 'I'.
Property 'alsoWorks' is missing in type 'C' but required in type 'I'.
fuzzy.ts(25,20): error TS2741: Property 'anything' is missing in type '{ oneI: this; }' but required in type 'R'.
fuzzy.ts(25,20): error TS2352: Conversion of type '{ oneI: this; }' to type 'R' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Property 'anything' is missing in type '{ oneI: this; }' but required in type 'R'.


==== fuzzy.ts (3 errors) ====
Expand Down Expand Up @@ -41,7 +42,8 @@ fuzzy.ts(25,20): error TS2741: Property 'anything' is missing in type '{ oneI: t
worksToo():R {
return <R>({ oneI: this });
~~~~~~~~~~~~~~~~~~~
!!! error TS2741: Property 'anything' is missing in type '{ oneI: this; }' but required in type 'R'.
!!! error TS2352: Conversion of type '{ oneI: this; }' to type 'R' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
!!! error TS2352: Property 'anything' is missing in type '{ oneI: this; }' but required in type 'R'.
!!! related TS2728 fuzzy.ts:9:9: 'anything' is declared here.
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ genericTypeAssertions2.ts(10,5): error TS2322: Type 'B<string>' is not assignabl
Types of parameters 'x' and 'x' are incompatible.
Type 'number' is not assignable to type 'string'.
genericTypeAssertions2.ts(11,5): error TS2741: Property 'bar' is missing in type 'A<number>' but required in type 'B<number>'.
genericTypeAssertions2.ts(13,21): error TS2741: Property 'foo' is missing in type 'undefined[]' but required in type 'A<number>'.
genericTypeAssertions2.ts(13,21): error TS2352: Conversion of type 'undefined[]' to type 'A<number>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Property 'foo' is missing in type 'undefined[]' but required in type 'A<number>'.


==== genericTypeAssertions2.ts (3 errors) ====
Expand All @@ -31,5 +32,6 @@ genericTypeAssertions2.ts(13,21): error TS2741: Property 'foo' is missing in typ
var r4: A<number> = <A<number>>new A();
var r5: A<number> = <A<number>>[]; // error
~~~~~~~~~~~~~
!!! error TS2741: Property 'foo' is missing in type 'undefined[]' but required in type 'A<number>'.
!!! error TS2352: Conversion of type 'undefined[]' to type 'A<number>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
!!! error TS2352: Property 'foo' is missing in type 'undefined[]' but required in type 'A<number>'.
!!! related TS2728 genericTypeAssertions2.ts:1:14: 'foo' is declared here.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
noImplicitAnyInCastExpression.ts(15,2): error TS2739: Type '{ c: null; }' is missing the following properties from type 'IFoo': a, b
noImplicitAnyInCastExpression.ts(15,2): error TS2352: Conversion of type '{ c: null; }' to type 'IFoo' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Type '{ c: null; }' is missing the following properties from type 'IFoo': a, b


==== noImplicitAnyInCastExpression.ts (1 errors) ====
Expand All @@ -18,4 +19,5 @@ noImplicitAnyInCastExpression.ts(15,2): error TS2739: Type '{ c: null; }' is mis
// Neither types is assignable to each other
(<IFoo>{ c: null });
~~~~~~~~~~~~~~~~~
!!! error TS2739: Type '{ c: null; }' is missing the following properties from type 'IFoo': a, b
!!! error TS2352: Conversion of type '{ c: null; }' to type 'IFoo' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
!!! error TS2352: Type '{ c: null; }' is missing the following properties from type 'IFoo': a, b

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
b.js(4,31): error TS2352: Conversion of type 'number' to type 'string' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
b.js(45,36): error TS2741: Property 'p' is missing in type 'SomeOther' but required in type 'SomeBase'.
b.js(49,42): error TS2739: Type 'SomeOther' is missing the following properties from type 'SomeDerived': p, x
b.js(51,38): error TS2741: Property 'q' is missing in type 'SomeDerived' but required in type 'SomeOther'.
b.js(52,38): error TS2741: Property 'q' is missing in type 'SomeBase' but required in type 'SomeOther'.
b.js(4,20): error TS2352: Conversion of type 'number' to type 'string' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
b.js(45,23): error TS2352: Conversion of type 'SomeOther' to type 'SomeBase' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Property 'p' is missing in type 'SomeOther' but required in type 'SomeBase'.
b.js(49,26): error TS2352: Conversion of type 'SomeOther' to type 'SomeDerived' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Type 'SomeOther' is missing the following properties from type 'SomeDerived': p, x
b.js(51,24): error TS2352: Conversion of type 'SomeDerived' to type 'SomeOther' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Property 'q' is missing in type 'SomeDerived' but required in type 'SomeOther'.
b.js(52,24): error TS2352: Conversion of type 'SomeBase' to type 'SomeOther' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Property 'q' is missing in type 'SomeBase' but required in type 'SomeOther'.
b.js(66,15): error TS1228: A type predicate is only allowed in return type position for functions and methods.
b.js(66,38): error TS2454: Variable 'numOrStr' is used before being assigned.
b.js(67,2): error TS2322: Type 'string | number' is not assignable to type 'string'.
Expand All @@ -18,7 +22,7 @@ b.js(67,8): error TS2454: Variable 'numOrStr' is used before being assigned.
var W = /** @type {string} */(/** @type {*} */ (4));

var W = /** @type {string} */(4); // Error
~
~~~~~~
!!! error TS2352: Conversion of type 'number' to type 'string' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.

/** @type {*} */
Expand Down Expand Up @@ -61,23 +65,27 @@ b.js(67,8): error TS2454: Variable 'numOrStr' is used before being assigned.
someBase = /** @type {SomeBase} */(someDerived);
someBase = /** @type {SomeBase} */(someBase);
someBase = /** @type {SomeBase} */(someOther); // Error
~~~~~~~~~
!!! error TS2741: Property 'p' is missing in type 'SomeOther' but required in type 'SomeBase'.
~~~~~~~~
!!! error TS2352: Conversion of type 'SomeOther' to type 'SomeBase' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
!!! error TS2352: Property 'p' is missing in type 'SomeOther' but required in type 'SomeBase'.
!!! related TS2728 b.js:17:9: 'p' is declared here.

someDerived = /** @type {SomeDerived} */(someDerived);
someDerived = /** @type {SomeDerived} */(someBase);
someDerived = /** @type {SomeDerived} */(someOther); // Error
~~~~~~~~~
!!! error TS2739: Type 'SomeOther' is missing the following properties from type 'SomeDerived': p, x
~~~~~~~~~~~
!!! error TS2352: Conversion of type 'SomeOther' to type 'SomeDerived' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
!!! error TS2352: Type 'SomeOther' is missing the following properties from type 'SomeDerived': p, x

someOther = /** @type {SomeOther} */(someDerived); // Error
~~~~~~~~~~~
!!! error TS2741: Property 'q' is missing in type 'SomeDerived' but required in type 'SomeOther'.
~~~~~~~~~
!!! error TS2352: Conversion of type 'SomeDerived' to type 'SomeOther' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
!!! error TS2352: Property 'q' is missing in type 'SomeDerived' but required in type 'SomeOther'.
!!! related TS2728 b.js:28:9: 'q' is declared here.
someOther = /** @type {SomeOther} */(someBase); // Error
~~~~~~~~
!!! error TS2741: Property 'q' is missing in type 'SomeBase' but required in type 'SomeOther'.
~~~~~~~~~
!!! error TS2352: Conversion of type 'SomeBase' to type 'SomeOther' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
!!! error TS2352: Property 'q' is missing in type 'SomeBase' but required in type 'SomeOther'.
!!! related TS2728 b.js:28:9: 'q' is declared here.
someOther = /** @type {SomeOther} */(someOther);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
objectTypesIdentityWithPrivates3.ts(25,1): error TS2741: Property 'y' is missing in type 'C3<T2>' but required in type 'C4'.
objectTypesIdentityWithPrivates3.ts(25,1): error TS2352: Conversion of type 'C3<T2>' to type 'C4' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Property 'y' is missing in type 'C3<T2>' but required in type 'C4'.


==== objectTypesIdentityWithPrivates3.ts (1 errors) ====
Expand Down Expand Up @@ -28,5 +29,6 @@ objectTypesIdentityWithPrivates3.ts(25,1): error TS2741: Property 'y' is missing
var c3: C3<T2>;
<C4>c3; // Should fail (private x originates in the same declaration, but different types)
~~~~~~
!!! error TS2741: Property 'y' is missing in type 'C3<T2>' but required in type 'C4'.
!!! error TS2352: Conversion of type 'C3<T2>' to type 'C4' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
!!! error TS2352: Property 'y' is missing in type 'C3<T2>' but required in type 'C4'.
!!! related TS2728 objectTypesIdentityWithPrivates3.ts:21:5: 'y' is declared here.

This file was deleted.

Loading
Loading