Skip to content

Commit 02885b1

Browse files
authored
Fixed an issue with top function type being callable with no arguments (#52387)
1 parent 6b75ce2 commit 02885b1

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34609,7 +34609,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3460934609

3461034610
function getNonArrayRestType(signature: Signature) {
3461134611
const restType = getEffectiveRestType(signature);
34612-
return restType && !isArrayType(restType) && !isTypeAny(restType) && (getReducedType(restType).flags & TypeFlags.Never) === 0 ? restType : undefined;
34612+
return restType && !isArrayType(restType) && !isTypeAny(restType) ? restType : undefined;
3461334613
}
3461434614

3461534615
function getTypeOfFirstParameterOfSignature(signature: Signature) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/compiler/topFunctionTypeNotCallable.ts(4,1): error TS2345: Argument of type '[]' is not assignable to parameter of type 'never'.
2+
3+
4+
==== tests/cases/compiler/topFunctionTypeNotCallable.ts (1 errors) ====
5+
// repro from #48840
6+
7+
declare let foo: (...args: never) => void;
8+
foo(); // error
9+
~~~~~
10+
!!! error TS2345: Argument of type '[]' is not assignable to parameter of type 'never'.
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/topFunctionTypeNotCallable.ts ===
2+
// repro from #48840
3+
4+
declare let foo: (...args: never) => void;
5+
>foo : Symbol(foo, Decl(topFunctionTypeNotCallable.ts, 2, 11))
6+
>args : Symbol(args, Decl(topFunctionTypeNotCallable.ts, 2, 18))
7+
8+
foo(); // error
9+
>foo : Symbol(foo, Decl(topFunctionTypeNotCallable.ts, 2, 11))
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/compiler/topFunctionTypeNotCallable.ts ===
2+
// repro from #48840
3+
4+
declare let foo: (...args: never) => void;
5+
>foo : (...args: never) => void
6+
>args : never
7+
8+
foo(); // error
9+
>foo() : void
10+
>foo : (...args: never) => void
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
// repro from #48840
5+
6+
declare let foo: (...args: never) => void;
7+
foo(); // error

0 commit comments

Comments
 (0)