mattpocock / ts-error-translator

VSCode extension to turn TypeScript errors into plain English
https://ts-error-translator.vercel.app
2.36k stars 90 forks source link

Backticks ` are not escaped properly in errors involving template literal types #254

Open Haltarys opened 7 months ago

Haltarys commented 7 months ago

Example code

declare function acceptsSuperhero(superhero: { name: `Super${string}` }): unknown;

acceptsSuperhero(1); // Argument of type 'number' is not assignable to parameter of type '{ name: `Super${string}`; }'. ts(2345)

image

Bug description

Currently, the backticks in the type '{ name: `Super${string}`; }' are not escaped when it is interpolated in the translation of the error message. They are instead interpreted as delimiters for inline code fences which messes up the display of the type in the error translation.

Expected behaviour

The types passed to the error message translations should be entirely escaped so that they are rendered properly.

Proposed fix

Maybe, one could reuse/reimplement the code from pretty-ts-errors to not only fix this issue, but also add syntax colouring to the types in the error translations. (See screenshot above.)