tsdjs / tsd

Check TypeScript type definitions
MIT License
2.36k stars 68 forks source link

feat(`diagnostic`): add missing error codes #177

Closed tommy-mitchell closed 1 year ago

tommy-mitchell commented 1 year ago

Fixes #170. Fixes #143.

Adds missing diagnostic codes:


Related, I think it's worth improving the error reporting when expectError fails. Currently, it reports

Expected an error, but found none.

even if another error is reported for the same invocation (i.e., tsd doesn't support that diagnostic code). We could change it to:

Expected an error, but found none. tsd may not currently support this error code, consider creating an issue on GitHub.

I used the following snippet in compiler.ts to confirm which DiagnosticCode to add[^1]:

if (ignoreDiagnosticResult === 'preserve') {
  console.log(diagnostic.code);
}

I think it would be worthwhile to either report the codes of all diagnostics (potentionally in a --verbose mode?), or at the very least in the expectError message:

let message = 'Expected an error, but found none.';

if (diagnostic.code) {
  message += ` tsd may not currently support \`ts${diagnostic.code}\`, consider creating an issue on GitHub.`;
}

[^1]: Full list here.

tommy-mitchell commented 1 year ago

Perhaps users could set additional diagnostic codes in their tsd config, to let their tests still pass if that code isn't in our list.

tommy-mitchell commented 1 year ago

Added ts2542 to fix #143.

sindresorhus commented 1 year ago

or at the very least in the expectError message:

👍

sindresorhus commented 1 year ago

or at the very least in the expectError message:

Do you plan to work on this? No pressure, but I need to know whether or not to release a new version after merging this.

tommy-mitchell commented 1 year ago

I did start attempting to add the updated error message, but it‘s a little more involved because the diagnostic object at that location doesn’t have access to the error code.

Should we just update the error message and add the code there, or report the code on all diagnostics?

sindresorhus commented 1 year ago

It would be too noisy to have the code on all diagnostics.