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
This commit is contained in:
Andrew Branch 2021-02-23 17:22:41 -08:00 committed by GitHub
parent 8d58c8d90b
commit 56cf2e68e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 1 deletions

View file

@ -28474,7 +28474,7 @@ namespace ts {
function isUntypedFunctionCall(funcType: Type, apparentFuncType: Type, numCallSignatures: number, numConstructSignatures: number): boolean {
// We exclude union types because we may have a union of function types that happen to have no common signatures.
return isTypeAny(funcType) || isTypeAny(apparentFuncType) && !!(funcType.flags & TypeFlags.TypeParameter) ||
!numCallSignatures && !numConstructSignatures && !(apparentFuncType.flags & (TypeFlags.Union | TypeFlags.Never)) && isTypeAssignableTo(funcType, globalFunctionType);
!numCallSignatures && !numConstructSignatures && !(apparentFuncType.flags & TypeFlags.Union) && !(getReducedType(apparentFuncType).flags & TypeFlags.Never) && isTypeAssignableTo(funcType, globalFunctionType);
}
function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[] | undefined, checkMode: CheckMode): Signature {

View file

@ -0,0 +1,11 @@
tests/cases/conformance/types/never/neverIntersectionNotCallable.ts(2,1): error TS2349: This expression is not callable.
Type 'never' has no call signatures.
==== tests/cases/conformance/types/never/neverIntersectionNotCallable.ts (1 errors) ====
declare const f: { (x: string): number, a: "" } & { a: number }
f()
~
!!! error TS2349: This expression is not callable.
!!! error TS2349: Type 'never' has no call signatures.

View file

@ -0,0 +1,7 @@
//// [neverIntersectionNotCallable.ts]
declare const f: { (x: string): number, a: "" } & { a: number }
f()
//// [neverIntersectionNotCallable.js]
f();

View file

@ -0,0 +1,10 @@
=== tests/cases/conformance/types/never/neverIntersectionNotCallable.ts ===
declare const f: { (x: string): number, a: "" } & { a: number }
>f : Symbol(f, Decl(neverIntersectionNotCallable.ts, 0, 13))
>x : Symbol(x, Decl(neverIntersectionNotCallable.ts, 0, 20))
>a : Symbol(a, Decl(neverIntersectionNotCallable.ts, 0, 39))
>a : Symbol(a, Decl(neverIntersectionNotCallable.ts, 0, 51))
f()
>f : Symbol(f, Decl(neverIntersectionNotCallable.ts, 0, 13))

View file

@ -0,0 +1,11 @@
=== tests/cases/conformance/types/never/neverIntersectionNotCallable.ts ===
declare const f: { (x: string): number, a: "" } & { a: number }
>f : never
>x : string
>a : ""
>a : number
f()
>f() : any
>f : never

View file

@ -0,0 +1,2 @@
declare const f: { (x: string): number, a: "" } & { a: number }
f()