Skip to content

Commit 18647c1

Browse files
authored
Document the custom CSS hack (#119)
* Add docs for the custom CSS hack * Bump version
1 parent 26048ed commit 18647c1

File tree

4 files changed

+75
-22
lines changed

4 files changed

+75
-22
lines changed

README.md

+26-21
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,66 @@
88

99
# Pretty `TypeScript` Errors
1010

11-
<b>Make TypeScript errors prettier and human-readable in VSCode.</b>
12-
11+
<b>Make TypeScript errors prettier and human-readable in VSCode.</b>
12+
1313
[![GitHub stars](https://img.shields.io/github/stars/yoavbls/pretty-ts-errors.svg?style=social&label=Star)](https://GitHub.com/yoavbls/pretty-ts-errors/stargazers/)
1414
[![Visual Studio Code](https://img.shields.io/badge/--007ACC?logo=visual%20studio%20code&logoColor=ffffff)](https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors)&nbsp;[![GitHub license](https://badgen.net/github/license/yoavbls/pretty-ts-errors)](https://github.com/yoavbls/pretty-ts-errors/blob/main/LICENSE)&nbsp;[![Visual Studio Code](https://img.shields.io/visual-studio-marketplace/i/yoavbls.pretty-ts-errors)](https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors)
1515
<a href="https://github.com/yoavbls/pretty-ts-errors/discussions/43#user-content-jetbrains-support"><img src="https://cdn.icon-icons.com/icons2/2530/PNG/512/jetbrains_webstorm_button_icon_151873.png" height="20" alt="Webstorm logo"></a>
1616

1717
TypeScript errors become messier as the complexity of types increases. At some point, TypeScript will throw on you a shitty heap of parentheses and `"..."`.
1818
This extension will help you understand what's going on. For example, in this relatively simple error:
1919

20-
<img src="./assets/this.png" width="340.438px" />&nbsp; &nbsp; <img src="./assets/instead-of-that.png" width="350px" />
21-
22-
20+
<img src="./assets/this.png" width="340.438px" />&nbsp; &nbsp; <img src="./assets/instead-of-that.png" width="350px" />
21+
2322
## Watch this
23+
2424
<a href="https://www.youtube.com/watch?v=9RM2aErJs-s" target="_blank">
2525
<img src="https://raw.githubusercontent.com/yoavbls/pretty-ts-errors/assets/assets/mentions/theo-video.png" alt="Watch theo's video" width="600" />
2626
</a>
2727

28-
and others from:
28+
and others from:
2929
[Web Dev Simplified](https://www.youtube.com/watch?v=ccg-erZYO4k&list=PL0rc4JAdEsVpOriHzlAG7KUnhKIK9c7OR&index=1),
3030
[Josh tried coding](https://www.youtube.com/watch?v=_9y29Cyo9uU&list=PL0rc4JAdEsVpOriHzlAG7KUnhKIK9c7OR&index=3),
3131
[trash dev](https://www.youtube.com/watch?v=WJeD3DKlWT4&list=PL0rc4JAdEsVpOriHzlAG7KUnhKIK9c7OR&index=4&t=208),
3232
and [more](https://www.youtube.com/playlist?list=PL0rc4JAdEsVpOriHzlAG7KUnhKIK9c7OR)
3333

34-
3534
## Features
35+
3636
- Syntax highlighting with your theme colors for types in error messages, supporting both light and dark themes
3737
- A button that leads you to the relevant type declaration next to the type in the error message
3838
- A button that navigates you to the error at [typescript.tv](http://typescript.tv), where you can find a detailed explanation, sometimes with a video
3939
- A button that navigates you to [ts-error-translator](https://ts-error-translator.vercel.app/), where you can read the error in plain English
4040

4141
## Supports
42+
4243
- Node and Deno TypeScript error reporters (in `.ts` files)
4344
- JSDoc type errors (in `.js` and `.jsx` files)
4445
- React, Solid and Qwik errors (in `.tsx` and `.mdx` files)
4546
- Astro, Svelte and Vue files when TypeScript is enabled (in `.astro`, `.svelte` and `.vue` files)
4647
- Ember and Glimmer TypeScript errors and template issues reported by Glint (in `.hbs`, `.gjs`, and `.gts` files)
47-
48-
48+
4949
## Installation
50+
5051
```
5152
code --install-extension yoavbls.pretty-ts-errors
5253
```
53-
Or simply by searching for `pretty-ts-errors` in the [VSCode marketplace](https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors)
54-
55-
54+
55+
Or simply by searching for `pretty-ts-errors` in the [VSCode marketplace](https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors)
56+
57+
#### How to hide the original errors and make the types copyable
58+
59+
Follow the instructions [there](./docs/hide-original-errors.md). unfortunately, this hack is required because of VSCode limitations.
60+
5661
## Why isn't it trivial
62+
5763
1. TypeScript errors contain types that are not valid in TypeScript.
58-
Yes, these types include things like `... more ...`, `{ ... }`, etc in an inconsistent manner. Some are also cutting in the middle because they're too long.
64+
Yes, these types include things like `... more ...`, `{ ... }`, etc in an inconsistent manner. Some are also cutting in the middle because they're too long.
5965
2. Types can't be syntax highlighted in code blocks because the part of `type X = ...` is missing, so I needed to create a new TextMate grammar, a superset of TypeScript grammar called `type`.
6066
3. VSCode markdown blocks all styling options, so I had to find hacks to style the error messages. e.g., there isn't an inlined code block on VSCode markdown, so I used a code block inside a codicon icon, which is the only thing that can be inlined. That's why it can't be copied. but it isn't a problem because you can still hover on the error and copy things from the original error pane.
61-
<img src="./assets/errors-hover.png" width="600" />
67+
<img src="./assets/errors-hover.png" width="600" />
6268

6369
## Hype section
70+
6471
<a href="https://www.youtube.com/live/Zze1y2iZ3bQ?si=Yj1Qw2S8FbGbTA5c&t=11589">
6572
<picture>
6673
<img width="400" src="https://github.com/yoavbls/pretty-ts-errors/blob/assets/assets/mentions/js-nation.png?raw=true" alt="Winning the Productivity Booster category at JSNation 2023">
@@ -88,8 +95,8 @@ Yes, these types include things like `... more ...`, `{ ... }`, etc in an incons
8895
</picture>
8996
</a>
9097

91-
92-
### Stars from stars
98+
### Stars from stars
99+
93100
<table>
94101
<tbody>
95102
<tr>
@@ -127,14 +134,12 @@ Yes, these types include things like `... more ...`, `{ ... }`, etc in an incons
127134
</tbody>
128135
</table>
129136

130-
131137
## Sponsorship
138+
132139
Every penny will be invested in other contributors to the project, especially ones that work
133140
on things that I can't be doing myself like adding support to the extension for other IDEs 🫂
134-
141+
135142
## Contribution
143+
136144
Help by upvoting or commenting on issues we need to be resolved [here](https://github.com/yoavbls/pretty-ts-errors/discussions/43)
137145
Any other contribution is welcome. Feel free to open any issue / PR you think.
138-
139-
140-

docs/hide-original-errors.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
To hide the original errors, display only the prettified ones, and make type blocks copyable, you can use the following hack:
2+
3+
## The Hack
4+
5+
1. Install the [Custom CSS and JS Loader](https://marketplace.visualstudio.com/items?itemName=be5invis.vscode-custom-css) extension from the VSCode marketplace.
6+
7+
2. Follow the installation instructions provided by the extension, and use [this CSS file](./pretty-ts-errors-hack.css).
8+
9+
## Why Do We Need This Hack?
10+
11+
### Hiding Original Errors
12+
13+
Unfortunately, VSCode doesn't currently support formatted diagnostics. Once it does, we'll be able to convert the extension to a TypeScript LSP Plugin that replaces the original error with the prettified version.
14+
For updates on this feature, follow [this issue](https://github.com/yoavbls/pretty-ts-errors/issues/3).
15+
16+
### Making Type Blocks Copyable
17+
18+
VSCode sanitizes and removes most CSS properties for security reasons. We've opened an [issue](https://github.com/microsoft/vscode/issues/180496) and submitted a [PR](https://github.com/microsoft/vscode/pull/180498) to allow the use of the `display` property. This would enable us to layout the types in a way that allows copying.
19+
20+
Until this change is approved, you can use the hack described above as a workaround.

docs/pretty-ts-errors-hack.css

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Allow copying */
2+
.codicon-none {
3+
user-select: text !important;
4+
-webkit-user-select: text !important;
5+
}
6+
7+
/* Hide errors */
8+
div.monaco-hover-content:has(.codicon-none) > .hover-row:first-child {
9+
display: none !important;
10+
}
11+
div.monaco-hover-content:has([style="color:#f96363;"]) > .hover-row:first-child {
12+
display: none !important
13+
}
14+
15+
/* Change order */
16+
.monaco-hover .monaco-hover-content {
17+
display: flex;
18+
flex-direction: column;
19+
}
20+
.monaco-hover .monaco-hover-content .hover-row {
21+
order: 2;
22+
}
23+
.monaco-hover .monaco-hover-content .hover-row:has(.codicon-none) {
24+
order: 1;
25+
}
26+
.monaco-hover .monaco-hover-content .hover-row:has([style="color:#f96363;"]) {
27+
order: 1;
28+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Pretty TypeScript Errors",
44
"publisher": "YoavBls",
55
"description": "Make TypeScript errors prettier and more human-readable in VSCode",
6-
"version": "0.6",
6+
"version": "0.6.0",
77
"icon": "assets/icon.png",
88
"repository": {
99
"type": "git",

0 commit comments

Comments
 (0)