question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regression causes Function top-type to be callable with no arguments

See original GitHub issue

Bug Report

🔎 Search Terms

function top type callable spread never regression

🕗 Version & Regression Information

  • This changed between versions 3.8.3 and 3.9.7

⏯ Playground Link

Playground link with relevant code

💻 Code

declare let foo: (...args: never) => void;
foo = (x: string) => {};
foo();  // no error

🙁 Actual behavior

foo() was permitted.

🙂 Expected behavior

foo() should not be permitted because it is unsafe. (...args: never) => unknown behaves as the top-type for all functions; all function types are assignable to it. So calling it will lead to unsafe behavior by functions expecting 1 or more arguments.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:16 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
tjjfvicommented, Oct 6, 2022

We shouldn’t even let you write declare let foo: (...args: never) => void;. It doesn’t make sense.

Are you saying that the type (...args: never) => void doesn’t make sense and should be removed? It seems perfectly logical as a top function type; the type of ...args is, in a sense, the intersection of all possible argument types, which is never. You can’t call a function of type (...args: never) => void, because you don’t know what arguments it takes, but you know that it is something that could be theoretically called, you just don’t know what it could be called with. It’s like {} being the top type of property-bearing things; you can’t directly access properties on it, because you don’t know what properties it might have, but you know that it has properties that could theoretically be accessed.

The second assignment isn’t unsound per our definition of rest args being assumed to have sufficient arity (or more accurately, it’s unsound in the way that all rest args / finite parameter lists are unsound)

Ah, good point.

1reaction
jcalzcommented, Dec 30, 2022

So, just running into this again, presumably declare const f: (...args: never[]) => unknown should allow f() because [] is assignable to never[], but declare const g: (...args: never) => unknown should not allow g() because [] is not assignable to never. And therefore (...args: never) => unknown is a top type for functions but (...args: never[]) => unknown shouldn’t be.

Right now both types are callable with no arguments and both of these are considered top types for functions. Which of these can we fix without breaking everyone?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Callable() takes no arguments - Python Help
You have to define a specific function to be called. You cannot call typing.Callable whose purpose is to be used just to describe...
Read more >
Type hinting Callable with no parameters - python
Is it possible to hint that the passed function receives no arguments? The correct way to type hint a Callable without arguments is...
Read more >
Abstract and composite types · Julia for Optimization and ...
A constructor is calling a type as a function. Two constructors are automatically generated when a type is created. One accepts any arguments...
Read more >
doc - Apple Open Source
No new tests as this doesn't surface as an issue when arguments are ... This patch makes some major changes to the way...
Read more >
Gradual Soundness: Lessons from Static Python - arXiv
first-class function (callable) types; and recursive types. Pyre and mypy have some support for the first two kinds, but no support for recursive...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found