question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow specifying diagnostic code in ts-expect-error

See original GitHub issue

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!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:18
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
IllusionMHcommented, Sep 17, 2021

Related discussion about specific codes: #19139 (I think there were similar topics about @ts-expect-error)

While I agree that it would be great to have more precise checks for errors - I think that proposals should address couple of concerns:

  1. error code after space might be common in existing code, how to avoid breaking them?
  2. error codes aren’t stable in TS and https://github.com/microsoft/TypeScript/issues/19139#issuecomment-641402113 (may require to open collapsed comments) should be also addressed in new proposals.
1reaction
markjmcommented, Oct 5, 2021

It is perhaps also worth noting that one of the reasonings for not supporting this functionality is to not support backwards integrations as errorCodes change, but VSCode TS extension uses these codes for a similar purpose.

https://github.com/microsoft/vscode/blob/99908438228fd427b33b45e8074195ccc312a020/extensions/typescript-language-features/src/utils/errorCodes.ts

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to write a Diagnostics TypeScript Language Service ...
PluginCreateInfo) { const proxy: ts.LanguageService = Object.create(null); for (let k of Object.keys(info.languageService) as Array<keyof ts.
Read more >
Improved Errors on Invalid Variable Names - Goldblog
I cleaned up the code changes, updated now-failing baseline tests, and sent it out for review: Specified error diagnostic for invalid variable ...
Read more >
ts-migrate: A Tool for Migrating to TypeScript at Scale - Medium
The allowJS config option allows us to have TypeScript and JavaScript files ... Based on the unique diagnostic code and the line number, ......
Read more >
April 2021 (version 1.56) - Visual Studio Code
To enable this feature, the debug.inlineValues setting has a new (default) value auto . When set to auto , inline values are automatically...
Read more >
Announcing Rome v11 - Rome Tools
You can help us by enabling the experimental rules in your configuration and providing feedback on the rule, the diagnostics, or the code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found