Fixed an issue with top function type being callable with no arguments (#52387)

This commit is contained in:
Mateusz Burzyński
2023-03-01 18:35:36 +01:00
committed by GitHub
parent 6b75ce23ce
commit 02885b1a2e
5 changed files with 40 additions and 1 deletions

View File

@@ -34609,7 +34609,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function getNonArrayRestType(signature: Signature) {
const restType = getEffectiveRestType(signature);
return restType && !isArrayType(restType) && !isTypeAny(restType) && (getReducedType(restType).flags & TypeFlags.Never) === 0 ? restType : undefined;
return restType && !isArrayType(restType) && !isTypeAny(restType) ? restType : undefined;
}
function getTypeOfFirstParameterOfSignature(signature: Signature) {

View File

@@ -0,0 +1,11 @@
tests/cases/compiler/topFunctionTypeNotCallable.ts(4,1): error TS2345: Argument of type '[]' is not assignable to parameter of type 'never'.
==== tests/cases/compiler/topFunctionTypeNotCallable.ts (1 errors) ====
// repro from #48840
declare let foo: (...args: never) => void;
foo(); // error
~~~~~
!!! error TS2345: Argument of type '[]' is not assignable to parameter of type 'never'.

View File

@@ -0,0 +1,10 @@
=== tests/cases/compiler/topFunctionTypeNotCallable.ts ===
// repro from #48840
declare let foo: (...args: never) => void;
>foo : Symbol(foo, Decl(topFunctionTypeNotCallable.ts, 2, 11))
>args : Symbol(args, Decl(topFunctionTypeNotCallable.ts, 2, 18))
foo(); // error
>foo : Symbol(foo, Decl(topFunctionTypeNotCallable.ts, 2, 11))

View File

@@ -0,0 +1,11 @@
=== tests/cases/compiler/topFunctionTypeNotCallable.ts ===
// repro from #48840
declare let foo: (...args: never) => void;
>foo : (...args: never) => void
>args : never
foo(); // error
>foo() : void
>foo : (...args: never) => void

View File

@@ -0,0 +1,7 @@
// @strict: true
// @noEmit: true
// repro from #48840
declare let foo: (...args: never) => void;
foo(); // error