-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
Bug Report
π Search Terms
default argument infer generic
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the entire FAQ
β― Playground Link
π» Code
const inferArg = <T extends [unknown?]>(f: (...args: T) => void): typeof f => f
// also no error in strict?
inferArg((start = 0) => {}) // <[start?: unknown]>
// ^?
inferArg((start: number = 0) => {}) // <[start?: number | undefined]>π Actual behavior
Infers start as unknown.
π Expected behavior
Infers start as number?. I expect the 2 calls to be equivalent.
Inference was a minor inconvenience because I'm using JSDoc. There's a separate DX issue that there was no compiler feedback on failed inference.
Is there already a ticket requesting an additional strict flag when a generic param can't be specialized and doesn't specify a default? I couldn't find it!
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug