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 justT
, 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).
Related Issues: #11062, but it's a different inconsistency (and has been fixed).