-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Inconsistency with Rest Parameter in Function Type #58552
Comments
I found this in the existing tests: Line 16 in 79a8514
This is a pretty old test though and it assumes // error
const fn1: (a?: string) => void = (a: string) => {}
// ok?
const fn2: (...args: number[]) => void = (x: number) => {}; We can find some recent tests with
At the very least |
Yeah, no. It can be up to an infinite number of params, but a minimum of zero. i.e. the same reason I guess the reasoning here is the same as how an object with a |
π Search Terms
rest parameters, parameter list, function parameters
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.4.5&ssl=5&ssc=12&pln=1&pc=1#code/C4TwDgpgBAysBOBLAdgcwGIFdkGNiIHtkoBeKACgDpqBDeVAZwC4oGEVUBtAXQEpSAfFABuBRABMA3AChpOImygQAHjQC2YADYQAjCzhI0WXPiKkKdVHtbs0-EkPnIGBbZU0FU5SzvcQ0wAAWvDLSKupauuQhQA
π» Code
π Actual behavior
This code does not display any type errors on any of the versions I tried, but will break at run time on the
example1()
call.π Expected behavior
Typescript should prevent the assignment of
(arg1: string) => void
to a variable of type(...args: string[]) => void
since it is possible to haveargs
be empty.Additional information about the issue
I attempted to search for other issues related to this and came up empty handed. This is different from the "I'm allowed to use a shorter parameter list where a longer one is expected" issue which has drowned out a lot of my searching.
Thanks in advance for any help with this.
The text was updated successfully, but these errors were encountered: