Skip to content

Inconsistent treatment of shorthand methods with generic Partial #32416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
russelldavis opened this issue Jul 16, 2019 · 2 comments · Fixed by #32594
Closed

Inconsistent treatment of shorthand methods with generic Partial #32416

russelldavis opened this issue Jul 16, 2019 · 2 comments · Fixed by #32594
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@russelldavis
Copy link
Contributor

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).

@russelldavis
Copy link
Contributor Author

#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).

@russelldavis
Copy link
Contributor Author

@RyanCavanaugh @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).

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jul 26, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.6.1 milestone Jul 26, 2019
@ahejlsberg ahejlsberg added the Fix Available A PR has been opened for this issue label Jul 28, 2019
@ahejlsberg ahejlsberg added Fixed A PR has been merged for this issue and removed Fix Available A PR has been opened for this issue labels Jul 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants