Description
Suggestion
π Search Terms
List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.
- 2775
- arrow
β Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
β Suggestion
const expectFoo = (bar: unknown): asserts bar is Foo => { ... };
This line should show a useful error message, like TSxxxx: Assertions cannot be used on a arrow-functions
π Motivating Example
π» Use Cases
Instead it shows TS2775: Assertions require every name in the call target to be declared with an explicit type annotation.
as error. And not where the assert
is, but instead where the function is called.
A better error message on this design limitation would have been nice instead of the confusing TS 2775
I also think this is extremely confusing. I just had to look that error up for the third time now, visiting the same StackOverflow post for the third time, and realizing that I had assertions on an arrow function again for the third time.
An error like TSxxxx: Assertions cannot be used on an arrow-function
would be much better.