-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
π Search Terms
error function optional required rest
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
function bar(a: number, b?: number, c: number, ...args: string[]) {}
bar
// ^? function bar(a: number, b?: number, c: number, ...args: string[]): void
bar(1); // Expected at least 3 arguments, but got 1.(2555)
function baz(a: number, b?: number, ...args: [c: number, ...args: string[]]) {}
baz
// ^? function baz(a: number, b?: number, c: number, ...args: string[]): void
baz(1); // Expected at least 3 arguments, but got 1.(2555)
π Actual behavior
We get an error within the bar
declaration ("'c' is declared but its value is never read.(6133)") but we get none in baz
. They are pretty much equivalent.
π Expected behavior
I'd expect this error to be raised consistently here (or not raised consistently).
In addition to that, b
comes with the question mark in both quick infos here. TypeScript understands that at least 3 arguments are required here. It means that effectively b
is required in both cases and ?
is somewhat misleading here. I think it would be good to normalize this. It already is normalized with tuples:
type A = [a: number, b?: number, ...[c: number, ...args: string[]]]
// ^? type A = [a: number, b: number | undefined, c: number, ...args: string[]]
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript