Skip to content

Inconsistent treatment of shorthand methods with generic Partial #32416

Closed

Description

TypeScript Version: 3.5.1

Search Terms: inconsistent shorthand methods

Code

function assignPartial<T>(target: T, partial: Partial<T>): T {
  return Object.assign(target, partial)
}

let obj = {
  foo(bar: string) {}
}

assignPartial(obj, {foo: (...args) => {}})
assignPartial(obj, {foo(...args) {}})

Expected behavior:
Both calls to assignPartial are typechecked the same, with no any types or errors.

Actual behavior:
In the second call, args is given the type any[], causing noImplicitAny to fail.

Additional notes:

  • If you change Partial<T> to just T, the error goes away (playground link).
  • If you keep Partial but hardcode the type instead of using generics, the error also goes away (playground link).

Playground Link:
https://www.typescriptlang.org/play/#code/ATBmFcDsGMBcEsD2lgEMDO74HNIAVUAnBVAGwB4AVAPgApYjsBTWALmEoBpgAHIk0uwLF4ZKtQCU7SsADeAKBAhCLcIRQB5AEYArJnAB0GLLnqMW3PiLITFwAL527pFsES7gAXjl2QoRIi0WkTs6LCE8JDYEnKOII52xjj4-KKktO463LL+iOy0BoWM6DGe1LH2tiBJuMICGbrZuQVFhNglFbZAA

Related Issues: #11062, but it's a different inconsistency (and has been fixed).

Activity

  1. russelldavis commented on Jul 16, 2019

    @russelldavis
    ContributorAuthor

    #32230 is related, however the fix for that bug does not fix this one (this bug persists in the latest nightly build, 3.6.0-dev.20190716).

  2. russelldavis commented on Jul 26, 2019

    @russelldavis
    ContributorAuthor

    Ryan Cavanaugh (@RyanCavanaugh) Anders Hejlsberg (@ahejlsberg) mind taking a quick look (at least to triage)? This is basically the same issue as #32230 (which was put in the 3.6 milestone and partially fixed, but this variant of the issue remains).

  3. added
    FixedA PR has been merged for this issue
    and removed
    Fix AvailableA PR has been opened for this issue
    on Jul 29, 2019
  4. locked as resolved and limited conversation to collaborators on Oct 21, 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 TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions