Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions tests/baselines/reference/topFunctionTypeNotCallable.errors.txt
Original file line number Diff line number Diff line change
@@ -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'.

10 changes: 10 additions & 0 deletions tests/baselines/reference/topFunctionTypeNotCallable.symbols
Original file line number Diff line number Diff line change
@@ -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))

11 changes: 11 additions & 0 deletions tests/baselines/reference/topFunctionTypeNotCallable.types
Original file line number Diff line number Diff line change
@@ -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

7 changes: 7 additions & 0 deletions tests/cases/compiler/topFunctionTypeNotCallable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @strict: true
// @noEmit: true

// repro from #48840

declare let foo: (...args: never) => void;
foo(); // error