Repository: yoavbls/pretty-ts-errors
Branch: main
Commit: 89b004805a2d
Files: 87
Total size: 113.9 KB
Directory structure:
gitextract_npj6yo6v/
├── .github/
│ ├── FUNDING.yml
│ ├── ISSUE_TEMPLATE/
│ │ └── bug_report.md
│ └── workflows/
│ └── pr-ci.yml
├── .gitignore
├── .prettierrc
├── .vscode/
│ ├── extensions.json
│ ├── launch.json
│ ├── settings.json
│ └── tasks.json
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── apps/
│ └── vscode-extension/
│ ├── .gitignore
│ ├── LICENSE
│ ├── package.json
│ ├── scripts/
│ │ ├── build.js
│ │ └── process-shim.js
│ ├── src/
│ │ ├── commands/
│ │ │ ├── copyError.ts
│ │ │ ├── execute.ts
│ │ │ ├── pinError.ts
│ │ │ ├── revealSelection.ts
│ │ │ ├── showErrorInSidebar.ts
│ │ │ ├── unpinError.ts
│ │ │ └── validate.ts
│ │ ├── diagnostics.ts
│ │ ├── extension.ts
│ │ ├── formattedDiagnosticsStore.ts
│ │ ├── globals.d.ts
│ │ ├── logger.ts
│ │ ├── provider/
│ │ │ ├── hoverProvider.ts
│ │ │ ├── markdownWebviewProvider.ts
│ │ │ ├── selectedTextHoverProvider.ts
│ │ │ └── webviewViewProvider.ts
│ │ ├── supportedLanguageIds.ts
│ │ └── test/
│ │ ├── runTest.ts
│ │ └── suite/
│ │ ├── extension.test.ts
│ │ └── index.ts
│ ├── syntaxes/
│ │ └── type.tmGrammar.json
│ ├── tsconfig.json
│ └── webview/
│ ├── index.html
│ ├── index.js
│ ├── style.css
│ └── vendor/
│ └── codicon.css
├── docs/
│ ├── hide-original-errors.md
│ ├── pretty-ts-errors-hack.css
│ └── vscode-logs.md
├── eslint.config.mjs
├── examples/
│ ├── errors.js
│ ├── errors.ts
│ ├── errors.vue
│ └── examples.type
├── package.json
├── packages/
│ ├── formatter/
│ │ ├── README.md
│ │ ├── package.json
│ │ ├── src/
│ │ │ ├── addMissingParentheses.ts
│ │ │ ├── errorMessagePrettifier.ts
│ │ │ ├── formatTypeBlock.ts
│ │ │ ├── formatTypeWithPrettier.ts
│ │ │ └── index.ts
│ │ ├── test/
│ │ │ ├── errorMessageMocks.ts
│ │ │ └── formatter.vitest.ts
│ │ ├── tsconfig.json
│ │ └── vitest.config.ts
│ ├── utils/
│ │ ├── package.json
│ │ ├── src/
│ │ │ └── index.ts
│ │ └── tsconfig.json
│ └── vscode-formatter/
│ ├── README.md
│ ├── package.json
│ ├── src/
│ │ ├── components/
│ │ │ ├── actions.ts
│ │ │ ├── errorTitle.ts
│ │ │ ├── hoverCodeBlock.ts
│ │ │ ├── htmlCodeBlock.ts
│ │ │ ├── miniLine.ts
│ │ │ ├── plainCodeBlock.ts
│ │ │ └── spanBreak.ts
│ │ ├── format/
│ │ │ ├── embedSymbolLinks.ts
│ │ │ ├── identSentences.ts
│ │ │ ├── prettifyDiagnosticForHover.ts
│ │ │ └── prettifyDiagnosticForSidebar.ts
│ │ └── index.ts
│ ├── test/
│ │ └── vscode-formatter.vitest.ts
│ ├── tsconfig.json
│ └── vitest.config.ts
├── tsconfig.base.json
├── tsconfig.json
├── tsdown.config.mjs
└── turbo.json
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/FUNDING.yml
================================================
github: [yoavbls, kevinramharak]
================================================
FILE: .github/ISSUE_TEMPLATE/bug_report.md
================================================
---
name: Bug report
about: Create a report to help us improve
title: ""
labels: bug
assignees: ""
---
### **Describe the bug**
A clear and concise description of what the bug is.
### **Expected behavior**
A clear and concise description of what you expected to happen.
### **Original error**
If this bug is related to an error that is not formatting well, please
attach the original error in a code block:
```
Type 'number' is not assignable to type 'string'.ts(2322)
```
### **Logs**
Add the logs to help debugging what went wrong. See [these instructions](https://github.com/yoavbls/pretty-ts-errors/blob/main/docs/vscode-logs.md) on how to find and export the logs.
Either add it as an external file or put them in between these `
` tags below:
Logs
### **Screenshots**
If applicable, add screenshots to help explain your problem.
================================================
FILE: .github/workflows/pr-ci.yml
================================================
name: PR CI
on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
permissions:
contents: read
concurrency:
group: pr-ci-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
validate:
name: Install, Build, and Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm install
- name: Install VSCE CLI
run: npm install -g @vscode/vsce
- name: Check formatting
run: npm run format:check
- name: Build all workspaces
run: npm run build
- name: Run formatter tests
run: npm -w @pretty-ts-errors/formatter run test -- --reporter=verbose
- name: Run VS Code formatter tests
run: npm -w @pretty-ts-errors/vscode-formatter run test -- --reporter=verbose
- name: Run VS Code extension tests
run: xvfb-run -a npm --workspace apps/vscode-extension run test
================================================
FILE: .gitignore
================================================
out
dist
node_modules
.vscode-test/
*.vsix
.turbo
.vercel
.idea
**/.DS_Store
tsconfig.tsbuildinfo
================================================
FILE: .prettierrc
================================================
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"trailingComma": "es5"
}
================================================
FILE: .vscode/extensions.json
================================================
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint",
"connor4312.esbuild-problem-matchers"
]
}
================================================
FILE: .vscode/launch.json
================================================
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/apps/vscode-extension"
],
"outFiles": [
"${workspaceFolder}/apps/vscode-extension/dist/**/*.js",
"${workspaceFolder}/apps/vscode-extension/out/**/*.js"
],
"preLaunchTask": "watch - apps/vscode-extension"
},
{
"name": "Run Extension (all extensions disabled)",
"type": "extensionHost",
"request": "launch",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}/apps/vscode-extension"
],
"outFiles": [
"${workspaceFolder}/apps/vscode-extension/dist/**/*.js",
"${workspaceFolder}/apps/vscode-extension/out/**/*.js"
],
"preLaunchTask": "watch - apps/vscode-extension"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/apps/vscode-extension",
"--extensionTestsPath=${workspaceFolder}/apps/vscode-extension/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/apps/vscode-extension/out/**/*.js",
"${workspaceFolder}/apps/vscode-extension/dist/**/*.js"
],
"preLaunchTask": "tasks: watch-tests"
}
]
}
================================================
FILE: .vscode/settings.json
================================================
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false, // set this to true to hide the "out" folder with the compiled JS files
"dist": false // set this to true to hide the "dist" folder with the compiled JS files
},
"search.exclude": {
"out": true, // set this to false to include "out" folder in search results
"dist": true // set this to false to include "dist" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"chat.tools.terminal.autoApprove": {
"npx vitest": true
}
}
================================================
FILE: .vscode/tasks.json
================================================
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"label": "watch - apps/vscode-extension",
"type": "shell",
"command": "npm run watch --silent",
"options": {
"cwd": "${workspaceFolder}/apps/vscode-extension"
},
"problemMatcher": {
"owner": "esbuild",
"fileLocation": "autoDetect",
"pattern": [
{
"regexp": "^✘ \\[ERROR\\] (.*)$",
"message": 1
},
{
"regexp": "^\\s*(.*):(\\d+):(\\d+):$",
"file": 1,
"line": 2,
"column": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": "^\\[watch\\] build started$",
"endsPattern": "^\\[watch\\] build finished$"
}
},
"isBackground": true,
"presentation": {
"reveal": "never",
"group": "watchers"
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "npm",
"script": "watch-tests",
"path": "apps/vscode-extension",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never",
"group": "watchers"
},
"group": "build"
},
{
"label": "tasks: watch-tests",
"dependsOn": ["watch - apps/vscode-extension", "npm: watch-tests"],
"problemMatcher": []
}
]
}
================================================
FILE: CONTRIBUTING.md
================================================
Contribute good stuff
If you're looking for ideas, check out our [board](https://github.com/users/yoavbls/projects/3) and [open issues](https://github.com/yoavbls/pretty-ts-errors/issues)
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2023 Yoav Balasiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# Pretty `TypeScript` Errors
Make TypeScript errors prettier and human-readable in VSCode.
[](https://GitHub.com/yoavbls/pretty-ts-errors/stargazers/)
[](https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors) [](https://github.com/yoavbls/pretty-ts-errors/blob/main/LICENSE) [](https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors)
[](https://open-vsx.org/extension/yoavbls/pretty-ts-errors)
TypeScript errors become messier as the complexity of types increases. At some point, TypeScript will throw on you a shitty heap of parentheses and `"..."`.
This extension will help you understand what's going on. For example, in this relatively simple error:
## Watch this
and others from:
[Web Dev Simplified](https://www.youtube.com/watch?v=ccg-erZYO4k&list=PL0rc4JAdEsVpOriHzlAG7KUnhKIK9c7OR&index=1),
[Josh tried coding](https://www.youtube.com/watch?v=_9y29Cyo9uU&list=PL0rc4JAdEsVpOriHzlAG7KUnhKIK9c7OR&index=3),
[trash dev](https://www.youtube.com/watch?v=WJeD3DKlWT4&list=PL0rc4JAdEsVpOriHzlAG7KUnhKIK9c7OR&index=4&t=208),
and [more](https://www.youtube.com/playlist?list=PL0rc4JAdEsVpOriHzlAG7KUnhKIK9c7OR)
## Features
- Syntax highlighting with your theme colors for types in error messages, supporting both light and dark themes
- A button that leads you to the relevant type declaration next to the type in the error message
- 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
- A button that navigates you to [ts-error-translator](https://ts-error-translator.vercel.app/), where you can read the error in plain English
## Supports
- Node and Deno TypeScript error reporters (in `.ts` files)
- JSDoc type errors (in `.js` and `.jsx` files)
- React, Solid and Qwik errors (in `.tsx` and `.mdx` files)
- Astro, Svelte and Vue files when TypeScript is enabled (in `.astro`, `.svelte` and `.vue` files)
- Ember and Glimmer TypeScript errors and template issues reported by Glint (in `.hbs`, `.gjs`, and `.gts` files)
## Installation
```
code --install-extension yoavbls.pretty-ts-errors
```
Or simply by searching for `pretty-ts-errors` in the [VSCode marketplace](https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors)
#### How to hide the original errors and make the types copyable
Follow the instructions [there](./docs/hide-original-errors.md). unfortunately, this hack is required because of VSCode limitations.
## Why isn't it trivial
1. TypeScript errors contain types that are not valid in TypeScript.
Yes, these types include things like `... more ...`, `{ ... }`, etc in an inconsistent manner. Some are also cutting in the middle because they're too long.
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`.
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.
## Hype section
### Stars from stars