Skip to content

Commit 56cf2e6

Browse files
authored
Never-reducing intersections are not untyped function call targets (#42917)
* Never-reducing intersections are not untyped function call targets * Don’t attempt to reduce union types
1 parent 8d58c8d commit 56cf2e6

File tree

6 files changed

+42
-1
lines changed

6 files changed

+42
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28474,7 +28474,7 @@ namespace ts {
2847428474
function isUntypedFunctionCall(funcType: Type, apparentFuncType: Type, numCallSignatures: number, numConstructSignatures: number): boolean {
2847528475
// We exclude union types because we may have a union of function types that happen to have no common signatures.
2847628476
return isTypeAny(funcType) || isTypeAny(apparentFuncType) && !!(funcType.flags & TypeFlags.TypeParameter) ||
28477-
!numCallSignatures && !numConstructSignatures && !(apparentFuncType.flags & (TypeFlags.Union | TypeFlags.Never)) && isTypeAssignableTo(funcType, globalFunctionType);
28477+
!numCallSignatures && !numConstructSignatures && !(apparentFuncType.flags & TypeFlags.Union) && !(getReducedType(apparentFuncType).flags & TypeFlags.Never) && isTypeAssignableTo(funcType, globalFunctionType);
2847828478
}
2847928479

2848028480
function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[] | undefined, checkMode: CheckMode): Signature {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/conformance/types/never/neverIntersectionNotCallable.ts(2,1): error TS2349: This expression is not callable.
2+
Type 'never' has no call signatures.
3+
4+
5+
==== tests/cases/conformance/types/never/neverIntersectionNotCallable.ts (1 errors) ====
6+
declare const f: { (x: string): number, a: "" } & { a: number }
7+
f()
8+
~
9+
!!! error TS2349: This expression is not callable.
10+
!!! error TS2349: Type 'never' has no call signatures.
11+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [neverIntersectionNotCallable.ts]
2+
declare const f: { (x: string): number, a: "" } & { a: number }
3+
f()
4+
5+
6+
//// [neverIntersectionNotCallable.js]
7+
f();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/conformance/types/never/neverIntersectionNotCallable.ts ===
2+
declare const f: { (x: string): number, a: "" } & { a: number }
3+
>f : Symbol(f, Decl(neverIntersectionNotCallable.ts, 0, 13))
4+
>x : Symbol(x, Decl(neverIntersectionNotCallable.ts, 0, 20))
5+
>a : Symbol(a, Decl(neverIntersectionNotCallable.ts, 0, 39))
6+
>a : Symbol(a, Decl(neverIntersectionNotCallable.ts, 0, 51))
7+
8+
f()
9+
>f : Symbol(f, Decl(neverIntersectionNotCallable.ts, 0, 13))
10+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/conformance/types/never/neverIntersectionNotCallable.ts ===
2+
declare const f: { (x: string): number, a: "" } & { a: number }
3+
>f : never
4+
>x : string
5+
>a : ""
6+
>a : number
7+
8+
f()
9+
>f() : any
10+
>f : never
11+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const f: { (x: string): number, a: "" } & { a: number }
2+
f()

0 commit comments

Comments
 (0)