Regression causes Function top-type to be callable with no arguments
See original GitHub issueBug 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:
- Created a year ago
- Reactions:1
- Comments:16 (13 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 isnever
. 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.Ah, good point.
So, just running into this again, presumably
declare const f: (...args: never[]) => unknown
should allowf()
because[]
is assignable tonever[]
, butdeclare const g: (...args: never) => unknown
should not allowg()
because[]
is not assignable tonever
. 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?