-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error TS2322: Improve nested interface message handling #20741
Comments
Sorry for poking over the holidays on this issue, but I was interested in trying to get this done during the holidays when (my) workload is low 💃 🕺 |
Given the way structural type checks happen, it is not clear that reversing the order of the messages would be ideal in the general case. in this specific case the absence of We are always looking for ways to make the errors more useful/approachable. so we are open to experimentation with new approaches. //CC @DanielRosenwasser |
I'm facing similar issues, and I would imagine with the addition of conditional typing, this problem is only going to increase in complexity. Given the example in the original problem space, would it be possible to indicate the specific problems as individual errors? This would easily allow indicating the errors as close to it's source as possible. Meaning, for an error on a nested property, you might see: const _example: Nestedthing = {
// Types of property 'a' are incompatible
a: { // Type '{ b: { c: string; }; }' is not assignable to type '{ b: { c: string; d: number; }; }'.
// Types of property 'b' are incompatible,
b: { // Type '{ c: string; }' is not assignable to type '{ c: string; d: number; }'
// Property 'd' is missing in type '{ c: string; }'.
c: "hi"
}
}
} As I think on this more, this should be doable in most editors assuming the error messages are structured in a way to allow for this, though output from |
vscode is going to support multi-lined errors - so also thinking about how this could be shown as a hierarchy of errors could be useful too. |
Might also be a good idea to see if there’s inspiration that could be drawn from Flow’s new error messages https://medium.com/flow-type/better-flow-error-messages-for-the-javascript-ecosystem-73b6da948ae2. |
A concrete suggesion I think works well: Ignore all parts of the type structures that are compatible until the first incompatible type with 2 or more incompatibilities. Show the types along the path that have a name, hide those that don't.
becomes:
|
The TS 3.0 error messages fix this well! I'm going to close this issue 👍 Thanks all. |
Actual behavior:
Gives an error like:
This example is pretty small, but the deeper the nesting, the longer the error message. These massages can get quite hard to dig right to the point:
An example from our codebase
We started teaching JS developers learning TypeScript to always "start at the end of a compiler message" - which isn't great ( this is compounded by VS Code only supporting single-line error messages in the problems section )
I wonder if it's possible to improve the error messaging to include a summary before the tree of 'how we got to that error'?
For example:
A pretty simple attack could be to take all the leaf nodes and show them beforehand in a separate section:
This:
A similar example based error output based on the real life error include above also:
We're happy to take a stab at implementing this, but you all have the most context around edge cases and what you want the messages to say.
/cc @damassi @alloy
The text was updated successfully, but these errors were encountered: