Skip to content

Confusing rules around function parameter names in a type #53933

Description

Bug Report

In auditing some code, I've noticed something that doesn't seem like it should compile. In >=4.95, the following code compiles without an issue, but in <=4.7.4, there is an error. Why is it possible to specify an object for the name of a parameter? This code was likely the result of a bad copy/paste, but TS isn't erroring on it. Am I missing something about the syntax? Also, is the discrepancy between versions intended?

const DEFAULT_NUM_PAGINATED_RESULTS = 10;
type IPaginatedParams = {first?: number; after?: string;}

type GetPaginatedResults = <Obj, Key extends keyof Obj>(

  items: Obj[],
  
  { first = DEFAULT_NUM_PAGINATED_RESULTS, after }: IPaginatedParams,
  
  key: Key
  
) => { items: Obj[]; hasMore: boolean };

Playground links for 4.7.4 vs 4.9.5

🔎 Search Terms

function parameter names

Activity

  1. typescript-bot commented on Apr 20, 2023

    @typescript-bot
    Contributor

    The change between origin/release-4.8 and origin/release-5.0 occurred at 3b45f4d.

  2. fatcerberus commented on Apr 20, 2023

    @fatcerberus

    That looks like… a valid destructuring, I think? The function takes an IPaginatedParams object as its second argument and then destructures it, extracting the first and after properties from it. It is kind of weird to do that in a function type though, since there’s no function body to use the extracted properties—all that matters there is the IPaginatedParams annotation.

  3. RyanCavanaugh commented on Apr 20, 2023

    @RyanCavanaugh
    Member

    Looks like an unintended consequence. Bisects to #49089

  4. RyanCavanaugh commented on Apr 20, 2023

    @RyanCavanaugh
    Member

    Minimal:

    // Should syntax error
    type Foo = ({ first = 0 }: { first?: number }) => unknown;
  5. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions