Open
Description
Suggestion
π Search Terms
return type, error message
β 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
Mention "return type" when return type of a function is not matching the declared type
When a parameter type is not matching the declared type, the error message has the words "parameter X" in it which makes it super easy to spot the error. For return types it only says type X is not compatible with type Y but is not clear that it is the return type
π Motivating Example
const func: (a: string, very: number, confusing: string, error: boolean, message: string) => string =
(a: string, very: number, confusing: string, error: boolean, message: string) => {
return 1
}
Error:
Type '(a: string, very: number, confusing: string, error: boolean, message: string) => number' is not assignable to type '(a: string, very: number, confusing: string, error: boolean, message: string) => string'.
Type 'number' is not assignable to type 'string'.(2322)
π» Use Cases
This can get tricky in very large and complex types. Just mentioning the word "return" can save a ton of time debugging issues