microsoft / microsoft/TypeScript
Improve error message for @ts-expect-error directive
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
I've just been looking for a way to "unit test" some quite complicated generic type signatures, and have just come across the @ts-expect-error and @ts-expect-no-error directives, which I think are fantastic for this kind of use case.
However, if I do something like this:
let myVar = 'bob';
// @ts-expect-error
myVar = 'fred';
The actual error I get is "Unused '@ts-expect-error' directive".
This makes it look as though the directive has been used incorrectly (which obviously it has in this very simple example), but this seems like it will be confusing for anyone subsequently involved in maintaining my code - because it looks as though all they need to do is remove the directive in order to fix the problem, whereas generally speaking, I will have put the directive there for a good reason, and if it's "unused" it means that somebody has broken the type signature logic.
Please could this error message be changed to shift the emphasis more onto the code being wrong, rather than the directive needing to be removed?
E.g.: "'@ts-expect-error' directive - this code should have failed type-checking, but didn't"
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the diagnostic that reports "Unused '@ts-expect-error' directive" and inspect the related compiler tests, if present. Update the wording so it emphasizes that the annotated code passed type-checking unexpectedly, then verify the example produces the revised diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100