Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 56cf2e6

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

6 files changed

+42-1Lines changed: 42 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+1-1Lines 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 {
Collapse file
+11Lines 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+
Collapse file
+7Lines 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();
Collapse file
+10Lines 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+
Collapse file
+11Lines 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+
Collapse file
+2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.