Equivalent arguments typed with tuples aren't assignable to the same functions with overloads when the same function is recursively referenced
See original GitHub issueBug Report
🔎 Search Terms
arguments, overloads, function, tuple
🕗 Version & Regression Information
All versions with support for tuple arguments (upto v4.5.0-dev.20210815).
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about function overloading (there is nothing in the FAQ about tuples)
⏯ Playground Link
Playground link with relevant code
💻 Code
type START = 0
type DATA = 1
type Args<In, Out> =
| [t: START, other: FnWithArgs<Out, In>]
| [t: DATA]
type FnWithArgs<In, Out> = (...args: Args<In, Out>) => void
interface FnWithOverloads<In, Out> {
(t: START, other: FnWithOverloads<Out, In>): void;
(t: DATA): void;
}
declare const withArgs: FnWithArgs<1, 2>
// these should be assignable to one another, but aren't:
const assertion: FnWithOverloads<1, 2> = withArgs
🙁 Actual behavior
Two types that should be functionally equivalent aren’t assignable to one another:
Type 'FnWithArgs<1, 2>' is not assignable to type 'FnWithOverloads<1, 2>'.
Types of parameters 'args' and 't' are incompatible.
Type '[t: 0, other: FnWithOverloads<2, 1>]' is not assignable to type 'Args<1, 2>'.
Type '[t: 0, other: FnWithOverloads<2, 1>]' is not assignable to type '[t: 0, other: FnWithArgs<2, 1>]'.
Type at position 1 in source is not compatible with type at position 1 in target.
Type 'FnWithOverloads<2, 1>' is not assignable to type 'FnWithArgs<2, 1>'.
Types of parameters 't' and 'args' are incompatible.
Type 'Args<2, 1>' is not assignable to type '[t: 0, other: FnWithOverloads<1, 2>]'.
Type '[t: 1]' is not assignable to type '[t: 0, other: FnWithOverloads<1, 2>]'.
Source has 1 element(s) but target requires 2.
I’ve tried simplifying the example, and this issue doesn’t seem to occur when the parameters of the function don’t reference themselves in their signature.
🙂 Expected behavior
No error, types should be assignable to one another.
Related issues
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How to have functions pass arguments with the same ...
You can just declare your pass function as being of the type of the original function using the typeof operator, e.g.
Read more >typing — Support for type hints — Python 3.11.1 documentation
In the function greeting , the argument name is expected to be of type str and the return type str . Subtypes are...
Read more >11. Recursion and exceptions - Computer Science
A tuple, like a list, is a sequence of items of any type. ... Syntax issues aside, tuples support the same sequence operations...
Read more >2.6. Supported Python features - Numba
Numba supports function calls using positional and named arguments, ... Numba is able to type-infer recursive functions without specifying the function type ......
Read more >Nim Tutorial (Part I) - Nim Programming Language
The assignment operator can be overloaded. You can declare multiple variables with a single assignment statement and all the variables will have the...
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 FreeTop 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
Top GitHub Comments
This is a correct analysis of what’s going wrong, but also a frequent source of complaint. Barring the problems of combinatorial explosion, this “should” work but doesn’t.
It means we’d like to see how many people 👍 this issue and comment with other solutions and ideas before considering it more.