Skip to content

Default argument doesn't constrain generic in higher-order function edge caseΒ #48480

@texastoland

Description

@texastoland

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

Workbench Repro

πŸ’» 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

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions