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).
TypeScript Version: 3.5.1
Search Terms: inconsistent shorthand methods
Code
Expected behavior:
Both calls to assignPartial are typechecked the same, with no
anytypes or errors.Actual behavior:
In the second call,
argsis given the typeany[], causingnoImplicitAnyto fail.Additional notes:
Partial<T>to justT, the error goes away (playground link).Partialbut 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).