TypeScript Version: 3.1
Search Terms: overload all errors
Code
declare function render(s: object, opts: { fileName: string }): void;
declare function render(s: string, name: string): void;
declare const obj: object;
// Actual error: cannot convert 'object' to 'string'
// Desired error: fileName / filename mismatch
render(obj, { filename: "foo" });
When multiple overloads with very different signatures exist, the ordering is effectively arbitrary. This creates really bad error messages when the "last" overload wasn't the one you were trying to call.
While some functions have an extremely large number of overloads, when there are only a few (< 5?) overloads, we should report their failures individually so that hopefully one of the error messages is useful.
e.g. instead of
TS2345: Argument of type 'object' is not assignable to parameter of type 'string'.
it should be
TSXXXX: Failed to find a suitable overload for this call
When invoking "(s: string, name: stri...":
TS2345: Argument of type 'object' is not assignable to parameter of type 'string'.
When invoking "(s: object, opts: { fl...":
TS2345: Argument of type '{ filename: string; }' is not assignable to parameter of type '{ fileName: string; }'.
Object literal may only specify known properties, but 'filename' does not exist in type '{ fileName: string; }'. Did you mean to write 'fileName'?
Playground Link: Link
Related Issues: #26633, others certainly exist
See also https://github.com/garybernhardt/preact-typescript-component-wont-build
TypeScript Version: 3.1
Search Terms: overload all errors
Code
When multiple overloads with very different signatures exist, the ordering is effectively arbitrary. This creates really bad error messages when the "last" overload wasn't the one you were trying to call.
While some functions have an extremely large number of overloads, when there are only a few (< 5?) overloads, we should report their failures individually so that hopefully one of the error messages is useful.
e.g. instead of
it should be
Playground Link: Link
Related Issues: #26633, others certainly exist
See also https://github.com/garybernhardt/preact-typescript-component-wont-build