microsoft / microsoft/TypeScript
Allow specifying diagnostic code in ts-expect-error
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Suggestion
🔍 Search Terms
ts-expect-error
✅ 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
Allow @ts-expect-error to specify diagnostic codes to be more precise in expectations.
Example:
// @ts-expect-error TS1234
Will only expect that diagnostic code. If the same line triggers a different diagnostic code, the expectation will error as if there was no error on the proceeding line.
📃 Motivating Example
This feature will be particularly useful when migrating code (1) between repositories with different TS configs, or even for (2) a slightly safer path when upgrading TS versions if all issues are not immediately fixed.
💻 Use Cases
The Teams Org is facing a code migration that I expect will benefit from this greatly. Please reach out to me (or I will come to office hours) and we can go through that example.
Code
I have attached a PR which implements the change as an example. Let me know what you think!
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 reviewing the attached example PR and the existing @ts-expect-error behavior described in the issue. Confirm how a diagnostic code should be parsed and matched, then add coverage showing that the expected code is accepted while a different or missing diagnostic causes an error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100