Typescript: Improve error messages for method chains

Created on 13 May 2019  路  6Comments  路  Source: microsoft/TypeScript

Search Terms

error call chain fluent api

Suggestion

In call chains some errors like TS2554 ("Expected x arguments, but got y") are reported for the whole call chain.

Example:

image

In this case the error is reported (starting) at line 5 where the actual error is in line 14.

Suggestion: Just highlight the concerned (last) method invocation in this case.

Use Cases

  • Fluent APIs: These sub-optimal error reporting is misguiding in fluent APIs because the start line number can be off hundreds of lines. Further, way too much is highlighted in red squiggles (for a single missing argument as in the example above).

Checklist

My suggestion meets these guidelines:

  • [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [x] This wouldn't change the runtime behavior of existing JavaScript code
  • [x] This could be implemented without emitting different JS based on the types of the expressions
  • [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • [x] This feature would agree with the rest of TypeScript's Design Goals.
Error Messages Experience Enhancement Fixed good first issue help wanted

Most helpful comment

Can I try this?

All 6 comments

indeed this is annoying, can we put some more effort to more precise/meaningful/drama-free error scopes?

@DanielRosenwasser This seems like pure win to me. Thoughts?

Daniel likes it per offline conversation. Accepting PRs to change the error span to just the method name + argument list.

Can I try this?

Go for it.

Thanks @dhruvrajvanshi!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jbondc picture jbondc  路  3Comments

Zlatkovsky picture Zlatkovsky  路  3Comments

bgrieder picture bgrieder  路  3Comments

kyasbal-1994 picture kyasbal-1994  路  3Comments

uber5001 picture uber5001  路  3Comments